xref: /titanic_50/usr/src/ucbcmd/stty/stty.c (revision b7f45089ccbe01bab3d7c7377b49d80d2ae18a69)
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 1995 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
28 /*	  All Rights Reserved  	*/
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 
33 #include <stdio.h>
34 #include <ctype.h>
35 #include <sys/types.h>
36 #include <termio.h>
37 #include <sys/stermio.h>
38 #include <sys/termiox.h>
39 #include "stty.h"
40 
41 extern char *getenv();
42 extern void exit();
43 extern void perror();
44 
45 static char	*STTY="stty: ";
46 static char	*USAGE="usage: stty [-agh] [modes]\n";
47 static int	pitt = 0;
48 static struct termios cb;
49 static struct termio ocb; /* for non-streams devices */
50 static struct stio stio;
51 static struct termiox termiox;
52 static struct winsize winsize, owinsize;
53 static int term;
54 
55 #define ioctl_desc	1
56 #define output		stderr
57 
58 main(argc, argv)
59 char	*argv[];
60 {
61 
62 	int i;
63 	char	*s_arg, *sttyparse();			/* s_arg: ptr to mode to be set */
64 	extern const struct	speeds	speeds[];
65 
66 	if (argc == 2) {
67 		/*
68 		 * "stty size", "stty speed" and "stty -g" are intended for
69 		 * use within backquotes; thus, they do the "fetch" "ioctl"
70 		 * from "/dev/tty" and always print their result on the
71 		 * standard output.
72 		 * Since their standard output is likely to be a pipe, they
73 		 * should not try to read the modes from the standard output.
74 		 */
75 		if (strcmp(argv[1], "size") == 0) {
76 			if ((i = open("/dev/tty", 0)) < 0) {
77 				perror("stty: Cannot open /dev/tty");
78 				exit(2);
79 			}
80 			if (ioctl(i, TIOCGWINSZ, &winsize) < 0) {
81 				perror("stty: TIOCGWINSZ");
82 				exit(2);
83 			}
84 			(void) printf("%d %d\n",winsize.ws_row,winsize.ws_col);
85 			exit(0);
86 		}
87 		else if (strcmp(argv[1], "speed") == 0) {
88 			if ((i = open("/dev/tty", 0)) < 0) {
89 				perror("stty: Cannot open /dev/tty");
90 				exit(2);
91 			}
92 			if((term = get_ttymode(i, &ocb, &cb, &stio, &termiox,
93 					&winsize)) < 0) {
94 				perror(STTY);
95 				exit(2);
96 			}
97 			if (term & TERMIOS) {
98 			    for(i=0; speeds[i].string; i++)
99 				if (cfgetospeed(&cb) == speeds[i].speed) {
100 					(void) printf("%s\n", speeds[i].string);
101 					exit(0);
102 				}
103 			} else {
104 			    for(i=0; speeds[i].string; i++)
105 				if ((cb.c_cflag&CBAUD) == speeds[i].speed) {
106 					(void) printf("%s\n", speeds[i].string);
107 					exit(0);
108 				}
109 			}
110 			(void) printf("unknown\n");
111 			exit(1);
112 		}
113                 else if (strcmp(argv[1], "-g") == 0) {
114 			if ((i = open("/dev/tty", 0)) < 0) {
115 				perror("stty: Cannot open /dev/tty");
116 				exit(2);
117 			}
118 			if((term = get_ttymode(i, &ocb, &cb, &stio, &termiox,
119 					&winsize)) < 0) {
120 				perror(STTY);
121 				exit(2);
122 			}
123 			prencode();
124 			exit(0);
125 		}
126 	}
127 
128 	if((term = get_ttymode(ioctl_desc, &ocb, &cb, &stio, &termiox, &winsize)) < 0) {
129 		perror(STTY);
130 		exit(2);
131 	}
132 	owinsize = winsize;
133 	if (argc == 1) {
134 		prmodes(0);
135 		exit(0);
136 	}
137 	if ((argc ==2) && strcmp(argv[1], "all") ==0) {
138 		prmodes(1);
139 		exit(0);
140 	}
141 	if ((argc ==2) && strcmp(argv[1], "everything") ==0) {
142 		pramodes(1);
143 		exit(0);
144 	}
145 	if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0'))
146 	switch(argv[1][1]) {
147 		case 'a':
148 			pramodes(0);
149 			exit(0);
150 		case 'h':
151 			pramodes(1);
152 			exit(0);
153 		default:
154 			(void) fprintf(stderr, "%s", USAGE);
155 			exit(2);
156 	}
157 	if (s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize)) {
158 		(void) fprintf(stderr, "unknown mode: %s\n", s_arg);
159 		exit(2);
160 	}
161 
162 	if(set_ttymode(ioctl_desc, term, &ocb, &cb, &stio, &termiox, &winsize, &owinsize) == -1) {
163 		perror(STTY);
164 		exit(2);
165 	}
166 	exit(0);	/*NOTREACHED*/
167 }
168 
169 prmodes(moremodes)			/* print modes, no options, argc is 1 */
170 int moremodes;
171 {
172 	register m;
173 
174 	if (!(term & ASYNC)) {
175 		m = stio.imode;
176 		if (m & IUCLC) (void) fprintf(output, "iuclc ");
177 		else (void) fprintf(output, "-iuclc ");
178 		m = stio.omode;
179 		if (m & OLCUC) (void) fprintf(output, "olcuc ");
180 		else (void) fprintf(output, "-olcuc ");
181 		if (m & TAB3) (void) fprintf(output, "tab3 ");
182 		m = stio.lmode;
183 		if (m & XCASE) (void) fprintf(output, "xcase ");
184 		else (void) fprintf(output, "-xcase ");
185 		if (m & STFLUSH) (void) fprintf(output, "stflush ");
186 		else (void) fprintf(output, "-stflush ");
187 		if (m & STWRAP) (void)fprintf(output, "stwrap ");
188 		else (void) fprintf(output, "-stwrap ");
189 		if (m & STAPPL) (void) fprintf(output, "stappl ");
190 		else (void) fprintf(output, "-stappl ");
191 		(void) fprintf(output, "\n");
192 	}
193 	if (term & ASYNC) {
194 		m = cb.c_cflag;
195 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
196 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
197 			prspeed("ispeed ", cfgetispeed(&cb));
198 			prspeed("ospeed ", cfgetospeed(&cb));
199 		} else
200 			prspeed("speed ", cfgetospeed(&cb));
201 		if (m&PARENB) {
202 			if((m&PAREXT) && (term & TERMIOS)) {
203 				if (m&PARODD)
204 					(void) fprintf(output,"markp ");
205 				else
206 					(void) fprintf(output,"spacep ");
207 			} else {
208 				if (m&PARODD)
209 					(void) fprintf(output,"oddp ");
210 				else
211 					(void) fprintf(output,"evenp ");
212 			}
213 		} else
214 			(void) fprintf(output,"-parity ");
215 		if(((m&PARENB) && !(m&CS7)) || (!(m&PARENB) && !(m&CS8)))
216 			(void) fprintf(output,"cs%c ",'5'+(m&CSIZE)/CS6);
217 		if (m&CSTOPB)
218 			(void) fprintf(output,"cstopb ");
219 		if (m&HUPCL)
220 			(void) fprintf(output,"hupcl ");
221 		if (!(m&CREAD))
222 			(void) fprintf(output,"-cread ");
223 		if (m&CLOCAL)
224 			(void) fprintf(output,"clocal ");
225 		if (m&LOBLK)
226 			(void) fprintf(output,"loblk ");
227 		(void) fprintf(output,"\n");
228 		if(ocb.c_line != 0)
229 			(void) fprintf(output,"line = %d; ", ocb.c_line);
230 		if(term & WINDOW) {
231 			(void)fprintf(output,"rows = %d; columns = %d;", winsize.ws_row, winsize.ws_col);
232 			(void)fprintf(output," ypixels = %d; xpixels = %d;\n", winsize.ws_ypixel, winsize.ws_xpixel);
233 		}
234 		if((cb.c_lflag&ICANON)== 0)
235 			(void) fprintf(output,"min = %d; time = %d;\n",
236 			cb.c_cc[VMIN], cb.c_cc[VTIME]);
237 		if (!moremodes) {
238 			if(cb.c_cc[VINTR] != CINTR)
239 				pit(cb.c_cc[VINTR], "intr", "; ");
240 			if(cb.c_cc[VQUIT] != CQUIT)
241 				pit(cb.c_cc[VQUIT], "quit", "; ");
242 			if(cb.c_cc[VERASE] != CERASE)
243 				pit(cb.c_cc[VERASE], "erase", "; ");
244 			if(cb.c_cc[VKILL] != CKILL)
245 				pit(cb.c_cc[VKILL], "kill", "; ");
246 			if(cb.c_cc[VEOF] != CEOF)
247 				pit(cb.c_cc[VEOF], "eof", "; ");
248 			if(cb.c_cc[VEOL] != CNUL)
249 				pit(cb.c_cc[VEOL], "eol", "; ");
250 			if(cb.c_cc[VEOL2] != CNUL)
251 				pit(cb.c_cc[VEOL2], "eol2", "; ");
252 			if(cb.c_cc[VSWTCH] != CSWTCH)
253 				pit(cb.c_cc[VSWTCH], "swtch", "; ");
254 			if(term & TERMIOS) {
255 				if(cb.c_cc[VSTART] != CSTART)
256 					pit(cb.c_cc[VSTART], "start", "; ");
257 				if(cb.c_cc[VSTOP] != CSTOP)
258 					pit(cb.c_cc[VSTOP], "stop", "; ");
259 				if(cb.c_cc[VSUSP] != CSUSP)
260 					pit(cb.c_cc[VSUSP], "susp", "; ");
261 				if(cb.c_cc[VDSUSP] != CDSUSP)
262 					pit(cb.c_cc[VDSUSP], "dsusp", "; ");
263 				if(cb.c_cc[VREPRINT] != CRPRNT)
264 					pit(cb.c_cc[VREPRINT], "rprnt", "; ");
265 				if(cb.c_cc[VDISCARD] != CFLUSH)
266 					pit(cb.c_cc[VDISCARD], "flush", "; ");
267 				if(cb.c_cc[VWERASE] != CWERASE)
268 					pit(cb.c_cc[VWERASE], "werase", "; ");
269 				if(cb.c_cc[VLNEXT] != CLNEXT)
270 					pit(cb.c_cc[VLNEXT], "lnext", "; ");
271 			}
272 		}
273 		if(pitt) (void) fprintf(output,"\n");
274 		m = cb.c_iflag;
275 		if (m&IGNBRK)
276 			(void) fprintf(output,"ignbrk ");
277 		else if (!(m&BRKINT))
278 			(void) fprintf(output,"-brkint ");
279 		if (!(m&INPCK))
280 			(void) fprintf(output,"-inpck ");
281 		else if (!(m&IGNPAR))
282 			(void) fprintf(output,"-ignpar ");
283 		if (m&PARMRK)
284 			(void) fprintf(output,"parmrk ");
285 		if (!(m&ISTRIP))
286 			(void) fprintf(output,"-istrip ");
287 		if (m&INLCR)
288 			(void) fprintf(output,"inlcr ");
289 		if (m&IGNCR)
290 			(void) fprintf(output,"igncr ");
291 		if (!(m&ICRNL))
292 			(void) fprintf(output,"-icrnl ");
293 		if (m&IUCLC)
294 			(void) fprintf(output,"iuclc ");
295 		if (!(m&IXON))
296 			(void) fprintf(output,"-ixon ");
297 		else if (m&IXANY)
298 			(void) fprintf(output,"ixany ");
299 		if (m&IXOFF)
300 			(void) fprintf(output,"ixoff ");
301 		if ((term & TERMIOS) && (m&IMAXBEL))
302 			(void) fprintf(output,"imaxbel ");
303 		m = cb.c_oflag;
304 		if (!(m&OPOST))
305 			(void) fprintf(output,"-opost ");
306 		else {
307 		if (m&OLCUC)
308 			(void) fprintf(output,"olcuc ");
309 		if (!(m&ONLCR))
310 			(void) fprintf(output,"-onlcr ");
311 		if (m&OCRNL)
312 			(void) fprintf(output,"ocrnl ");
313 		if (m&ONOCR)
314 			(void) fprintf(output,"onocr ");
315 		if (m&ONLRET)
316 			(void) fprintf(output,"onlret ");
317 		if (m&OFILL)
318 			if (m&OFDEL)
319 				(void) fprintf(output,"del-fill ");
320 			else
321 				(void) fprintf(output,"nul-fill ");
322 		delay((m&CRDLY)/CR1, "cr");
323 		delay((m&NLDLY)/NL1, "nl");
324 		if ((m&TABDLY) == XTABS)
325 			(void) fprintf(output,"-tabs ");
326 		else
327 			delay((m&TABDLY)/TAB1, "tab");
328 		delay((m&BSDLY)/BS1, "bs");
329 		delay((m&VTDLY)/VT1, "vt");
330 		delay((m&FFDLY)/FF1, "ff");
331 		}
332 		(void) fprintf(output,"\n");
333 		m = cb.c_lflag;
334 		if (!(m&ISIG))
335 			(void) fprintf(output,"-isig ");
336 		if (!(m&ICANON))
337 			(void) fprintf(output,"-icanon ");
338 		if (m&XCASE)
339 			(void) fprintf(output,"xcase ");
340 		if (!(m&ECHO))
341 			(void) fprintf(output,"-echo ");
342 		if (m&ECHOE) {
343 			if (m&ECHOKE)
344 				(void) fprintf(output,"crt ");
345 			else
346 				(void) fprintf(output,"echoe -echoke ");
347 		} else {
348 			if (!(m&ECHOPRT))
349 				(void) fprintf(output,"-echoprt ");
350 		}
351 		if (!(m&ECHOK))
352 			(void) fprintf(output,"-echok ");
353 		if (m&ECHONL)
354 			(void) fprintf(output,"echonl ");
355 		if (m&NOFLSH)
356 			(void) fprintf(output,"noflsh ");
357 		if (m&TOSTOP)
358 			(void) fprintf(output,"tostop ");
359 		if (!(m&ECHOCTL))
360 			(void) fprintf(output,"-echoctl ");
361 		if (m&DEFECHO)
362 			(void) fprintf(output,"defecho ");
363 		if (m&FLUSHO)
364 			(void) fprintf(output,"flusho ");
365 		if (m&PENDIN)
366 			(void) fprintf(output,"pendin ");
367 		if (m&IEXTEN)
368 			(void) fprintf(output,"iexten ");
369 		(void) fprintf(output,"\n");
370 	}
371 	if(term & FLOW) {
372 		m = termiox.x_hflag;
373 		if(m & RTSXOFF)
374 			(void) fprintf(output,"rtsxoff ");
375 		if(m & CTSXON)
376 			(void) fprintf(output,"ctsxon ");
377 		if(m & DTRXOFF)
378 			(void) fprintf(output,"dterxoff ");
379 		if(m & CDXON)
380 			(void) fprintf(output,"rlsdxon ");
381 		if(m & ISXOFF)
382 			(void) fprintf(output,"isxoff ");
383 		m = termiox.x_cflag;
384 		switch(m & XMTCLK)
385 		{
386 			case XCIBRG: (void)fprintf(output,"xcibrg ");
387 				     break;
388 			case XCTSET: (void)fprintf(output,"xctset ");
389 				     break;
390 			case XCRSET: (void)fprintf(output,"xcrset ");
391 		}
392 
393 		switch(m & RCVCLK)
394 		{
395 			case RCIBRG: (void)fprintf(output,"rcibrg ");
396 				     break;
397 			case RCTSET: (void)fprintf(output,"rctset ");
398 				     break;
399 			case RCRSET: (void)fprintf(output,"rcrset ");
400 		}
401 
402 		switch(m & TSETCLK)
403 		{
404 			case TSETCOFF: (void)fprintf(output,"tsetcoff ");
405 				     break;
406 			case TSETCRBRG: (void)fprintf(output,"tsetcrc ");
407 				     break;
408 			case TSETCTBRG: (void)fprintf(output,"tsetcxc ");
409 		}
410 
411 		switch(m & RSETCLK)
412 		{
413 			case RSETCOFF: (void)fprintf(output,"rsetcoff ");
414 				     break;
415 			case RSETCRBRG: (void)fprintf(output,"rsetcrc ");
416 				     break;
417 			case RSETCTBRG: (void)fprintf(output,"rsetcxc ");
418 		}
419 		(void) fprintf(output,"\n");
420 	}
421 	if(moremodes)
422 		prachars();
423 }
424 
425 pramodes(tabform)			/* print all modes, -a option */
426 int tabform;
427 {
428 	register m;
429 
430 	m = cb.c_cflag;
431 	if(term & ASYNC) {
432 		if ((term & TERMIOS) && cfgetispeed(&cb) != 0 &&
433 		    cfgetispeed(&cb) != cfgetospeed(&cb)) {
434 			prspeed("ispeed ", cfgetispeed(&cb));
435 			prspeed("ospeed ", cfgetospeed(&cb));
436 		} else
437 			prspeed("speed ", cfgetospeed(&cb));
438 		if(!(term & TERMIOS))
439 			(void) fprintf(output,"line = %d; ", ocb.c_line);
440 		(void) fprintf(output,"\n");
441 		if(term & WINDOW) {
442 			(void)fprintf(output,"rows = %d columns = %d; ", winsize.ws_row, winsize.ws_col);
443 			(void)fprintf(output,"ypixels = %d xpixels = %d\n", winsize.ws_ypixel, winsize.ws_xpixel);
444 		}
445 		if((cb.c_lflag&ICANON)== 0)
446 			(void) fprintf(output,"min = %d; time = %d;\n", cb.c_cc[VMIN],
447 			cb.c_cc[VTIME]);
448 		if (!tabform) {
449 			pit(cb.c_cc[VINTR], "intr", "; ");
450 			pit(cb.c_cc[VQUIT], "quit", "; ");
451 			pit(cb.c_cc[VERASE], "erase", "; ");
452 			pit(cb.c_cc[VKILL], "kill", ";\n");
453 			pit(cb.c_cc[VEOF], "eof", "; ");
454 			pit(cb.c_cc[VEOL], "eol", "; ");
455 			pit(cb.c_cc[VEOL2], "eol2", "; ");
456 			pit(cb.c_cc[VSWTCH], "swtch", ";\n");
457 			if(term & TERMIOS) {
458 				pit(cb.c_cc[VSTART], "start", "; ");
459 				pit(cb.c_cc[VSTOP], "stop", "; ");
460 				pit(cb.c_cc[VSUSP], "susp", "; ");
461 				pit(cb.c_cc[VDSUSP], "dsusp", ";\n");
462 				pit(cb.c_cc[VREPRINT], "rprnt", "; ");
463 				pit(cb.c_cc[VDISCARD], "flush", "; ");
464 				pit(cb.c_cc[VWERASE], "werase", "; ");
465 				pit(cb.c_cc[VLNEXT], "lnext", ";\n");
466 			}
467 		}
468 	} else
469 		pit((unsigned)stio.tab, "ctab", "\n");
470 	m = cb.c_cflag;
471 	(void) fprintf(output,"-parenb "+((m&PARENB)!=0));
472 	(void) fprintf(output,"-parodd "+((m&PARODD)!=0));
473 	(void) fprintf(output,"cs%c ",'5'+(m&CSIZE)/CS6);
474 	(void) fprintf(output,"-cstopb "+((m&CSTOPB)!=0));
475 	(void) fprintf(output,"-hupcl "+((m&HUPCL)!=0));
476 	(void) fprintf(output,"-cread "+((m&CREAD)!=0));
477 	(void) fprintf(output,"-clocal "+((m&CLOCAL)!=0));
478 
479 	(void) fprintf(output,"-loblk "+((m&LOBLK)!=0));
480 	if(term & TERMIOS)
481 		(void) fprintf(output,"-parext "+((m&PAREXT)!=0));
482 
483 	(void) fprintf(output,"\n");
484 	m = cb.c_iflag;
485 	(void) fprintf(output,"-ignbrk "+((m&IGNBRK)!=0));
486 	(void) fprintf(output,"-brkint "+((m&BRKINT)!=0));
487 	(void) fprintf(output,"-ignpar "+((m&IGNPAR)!=0));
488 	(void) fprintf(output,"-parmrk "+((m&PARMRK)!=0));
489 	(void) fprintf(output,"-inpck "+((m&INPCK)!=0));
490 	(void) fprintf(output,"-istrip "+((m&ISTRIP)!=0));
491 	(void) fprintf(output,"-inlcr "+((m&INLCR)!=0));
492 	(void) fprintf(output,"-igncr "+((m&IGNCR)!=0));
493 	(void) fprintf(output,"-icrnl "+((m&ICRNL)!=0));
494 	(void) fprintf(output,"-iuclc "+((m&IUCLC)!=0));
495 	(void) fprintf(output,"\n");
496 	(void) fprintf(output,"-ixon "+((m&IXON)!=0));
497 	(void) fprintf(output,"-ixany "+((m&IXANY)!=0));
498 	(void) fprintf(output,"-ixoff "+((m&IXOFF)!=0));
499 	if(term & TERMIOS)
500 		(void) fprintf(output,"-imaxbel "+((m&IMAXBEL)!=0));
501 	(void) fprintf(output,"\n");
502 	m = cb.c_lflag;
503 	(void) fprintf(output,"-isig "+((m&ISIG)!=0));
504 	(void) fprintf(output,"-icanon "+((m&ICANON)!=0));
505 	(void) fprintf(output,"-xcase "+((m&XCASE)!=0));
506 	(void) fprintf(output,"-echo "+((m&ECHO)!=0));
507 	(void) fprintf(output,"-echoe "+((m&ECHOE)!=0));
508 	(void) fprintf(output,"-echok "+((m&ECHOK)!=0));
509 	(void) fprintf(output,"-echonl "+((m&ECHONL)!=0));
510 	(void) fprintf(output,"-noflsh "+((m&NOFLSH)!=0));
511 	if(term & TERMIOS) {
512 		(void) fprintf(output,"\n");
513 		(void) fprintf(output,"-tostop "+((m&TOSTOP)!=0));
514 		(void) fprintf(output,"-echoctl "+((m&ECHOCTL)!=0));
515 		(void) fprintf(output,"-echoprt "+((m&ECHOPRT)!=0));
516 		(void) fprintf(output,"-echoke "+((m&ECHOKE)!=0));
517 		(void) fprintf(output,"-defecho "+((m&DEFECHO)!=0));
518 		(void) fprintf(output,"-flusho "+((m&FLUSHO)!=0));
519 		(void) fprintf(output,"-pendin "+((m&PENDIN)!=0));
520 		(void) fprintf(output,"-iexten "+((m&IEXTEN)!=0));
521 	}
522 	if(!(term & ASYNC)) {
523 		(void) fprintf(output,"-stflush "+((m&STFLUSH)!=0));
524 		(void) fprintf(output,"-stwrap "+((m&STWRAP)!=0));
525 		(void) fprintf(output,"-stappl "+((m&STAPPL)!=0));
526 	}
527 	(void) fprintf(output,"\n");
528 	m = cb.c_oflag;
529 	(void) fprintf(output,"-opost "+((m&OPOST)!=0));
530 	(void) fprintf(output,"-olcuc "+((m&OLCUC)!=0));
531 	(void) fprintf(output,"-onlcr "+((m&ONLCR)!=0));
532 	(void) fprintf(output,"-ocrnl "+((m&OCRNL)!=0));
533 	(void) fprintf(output,"-onocr "+((m&ONOCR)!=0));
534 	(void) fprintf(output,"-onlret "+((m&ONLRET)!=0));
535 	(void) fprintf(output,"-ofill "+((m&OFILL)!=0));
536 	(void) fprintf(output,"-ofdel "+((m&OFDEL)!=0));
537 	delay((m&CRDLY)/CR1, "cr");
538 	delay((m&NLDLY)/NL1, "nl");
539 	if ((m&TABDLY) == XTABS)
540 		(void) fprintf(output,"-tabs ");
541 	else
542 		delay((m&TABDLY)/TAB1, "tab");
543 	delay((m&BSDLY)/BS1, "bs");
544 	delay((m&VTDLY)/VT1, "vt");
545 	delay((m&FFDLY)/FF1, "ff");
546 	(void) fprintf(output,"\n");
547 	if(term & FLOW) {
548 		m = termiox.x_hflag;
549 		(void) fprintf(output,"-rtsxoff "+((m&RTSXOFF)!=0));
550 		(void) fprintf(output,"-ctsxon "+((m&CTSXON)!=0));
551 		(void) fprintf(output,"-dterxoff "+((m&DTRXOFF)!=0));
552 		(void) fprintf(output,"-rlsdxon "+((m&CDXON)!=0));
553 		(void) fprintf(output,"-isxoff "+((m&ISXOFF)!=0));
554 		m = termiox.x_cflag;
555 		switch(m & XMTCLK)
556 		{
557 			case XCIBRG: (void)fprintf(output,"xcibrg ");
558 				     break;
559 			case XCTSET: (void)fprintf(output,"xctset ");
560 				     break;
561 			case XCRSET: (void)fprintf(output,"xcrset ");
562 		}
563 
564 		switch(m & RCVCLK)
565 		{
566 			case RCIBRG: (void)fprintf(output,"rcibrg ");
567 				     break;
568 			case RCTSET: (void)fprintf(output,"rctset ");
569 				     break;
570 			case RCRSET: (void)fprintf(output,"rcrset ");
571 		}
572 
573 		switch(m & TSETCLK)
574 		{
575 			case TSETCOFF: (void)fprintf(output,"tsetcoff ");
576 				     break;
577 			case TSETCRBRG: (void)fprintf(output,"tsetcrc ");
578 				     break;
579 			case TSETCTBRG: (void)fprintf(output,"tsetcxc ");
580 		}
581 
582 		switch(m & RSETCLK)
583 		{
584 			case RSETCOFF: (void)fprintf(output,"rsetcoff ");
585 				     break;
586 			case RSETCRBRG: (void)fprintf(output,"rsetcrc ");
587 				     break;
588 			case RSETCTBRG: (void)fprintf(output,"rsetcxc ");
589 		}
590 		(void) fprintf(output,"\n");
591 	}
592 	if (tabform)
593 		prachars();
594 }
595 
596 prachars()
597 {
598 	if ((cb.c_lflag&ICANON)==0)
599 		(void) fprintf(output,"min %d, time %d\n", cb.c_cc[VMIN],
600 		    cb.c_cc[VTIME]);
601 	(void) fprintf(output,"\
602 erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof\
603 \n");
604 	pcol(cb.c_cc[VERASE], 0);
605 	pcol(cb.c_cc[VKILL], 0);
606 	pcol(cb.c_cc[VWERASE], 0);
607 	pcol(cb.c_cc[VREPRINT], 0);
608 	pcol(cb.c_cc[VDISCARD], 0);
609 	pcol(cb.c_cc[VLNEXT], 0);
610 	pcol(cb.c_cc[VSUSP], cb.c_cc[VDSUSP]);
611 	pcol(cb.c_cc[VINTR], 0);
612 	pcol(cb.c_cc[VQUIT], 0);
613 	pcol(cb.c_cc[VSTOP], cb.c_cc[VSTART]);
614 	if (cb.c_lflag&ICANON)
615 		pcol(cb.c_cc[VEOF], cb.c_cc[VEOL]);
616 	(void) fprintf(output,"\n");
617 	if (cb.c_cc[VEOL2] != 0 || cb.c_cc[VSWTCH] != 0) {
618 		(void) fprintf(output,"\
619 eol2  swtch\
620 \n");
621 		pcol(cb.c_cc[VEOL2], 0);
622 		pcol(cb.c_cc[VSWTCH], 0);
623 		(void) fprintf(output,"\n");
624 	}
625 }
626 
627 pcol(ch1, ch2)
628 	int ch1, ch2;
629 {
630 	int nout = 0;
631 
632 	ch1 &= 0377;
633 	ch2 &= 0377;
634 	if (ch1 == ch2)
635 		ch2 = 0;
636 	for (; ch1 != 0 || ch2 != 0; ch1 = ch2, ch2 = 0) {
637 		if (ch1 == 0)
638 			continue;
639 		if (ch1 & 0200 && !isprint(ch1)) {
640 			(void) fprintf(output,"M-");
641 			nout += 2;
642 			ch1 &= ~ 0200;
643 		}
644 		if (ch1 == 0177) {
645 			(void) fprintf(output,"^");
646 			nout++;
647 			ch1 = '?';
648 		} else if (ch1 < ' ') {
649 			(void) fprintf(output,"^");
650 			nout++;
651 			ch1 += '@';
652 		}
653 		(void) fprintf(output,"%c", ch1);
654 		nout++;
655 		if (ch2 != 0) {
656 			(void) fprintf(output,"/");
657 			nout++;
658 		}
659 	}
660 	while (nout < 7) {
661 		(void) fprintf(output," ");
662 		nout++;
663 	}
664 }
665 
666 
667 pit(what, itsname, sep)		/*print function for prmodes() and pramodes() */
668 	unsigned char what;
669 	char *itsname, *sep;
670 {
671 
672 	pitt++;
673 	(void) fprintf(output,"%s", itsname);
674 	if ((term & TERMIOS) && what == _POSIX_VDISABLE || !(term & TERMIOS) && what == 0200) {
675 		(void) fprintf(output," = <undef>%s", sep);
676 		return;
677 	}
678 	(void) fprintf(output," = ");
679 	if (what & 0200 && !isprint(what)) {
680 		(void) fprintf(output,"-");
681 		what &= ~ 0200;
682 	}
683 	if (what == 0177) {
684 		(void) fprintf(output,"^?%s", sep);
685 		return;
686 	} else if (what < ' ') {
687 		(void) fprintf(output,"^");
688 		what += '`';
689 	}
690 	(void) fprintf(output,"%c%s", what, sep);
691 }
692 
693 delay(m, s)
694 char *s;
695 {
696 	if(m)
697 		(void) fprintf(output,"%s%d ", s, m);
698 }
699 
700 long	speed[] = {
701 	0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400,
702 	57600,76800,115200,153600,230400,307200,460800
703 };
704 
705 prspeed(c, s)
706 char *c;
707 int s;
708 {
709 
710 	(void) fprintf(output,"%s%d baud; ", c, speed[s]);
711 }
712 
713 					/* print current settings for use with  */
714 prencode()				/* another stty cmd, used for -g option */
715 {
716 	int i, last;
717 
718 	/* Since the -g option is mostly used for redirecting to a file *
719 	/* We must print to stdout here, not stderr */
720 
721 	(void) printf("%x:%x:%x:%x:",cb.c_iflag,cb.c_oflag,cb.c_cflag,cb.c_lflag);
722 
723 	if(term & TERMIOS)
724 	/* last control slot is unused */
725 		last = NCCS - 2;
726 	else
727 		last = NCC - 1;
728 	for(i = 0; i < last; i++)
729 		(void) printf("%x:", cb.c_cc[i]);
730 	(void) printf("%x\n", cb.c_cc[last]);
731 }
732