xref: /csrg-svn/bin/stty/stty.c (revision 25791)
119907Sdist /*
219907Sdist  * Copyright (c) 1980 Regents of the University of California.
319907Sdist  * All rights reserved.  The Berkeley software License Agreement
419907Sdist  * specifies the terms and conditions for redistribution.
519907Sdist  */
619907Sdist 
713073Ssam #ifndef lint
819907Sdist char copyright[] =
919907Sdist "@(#) Copyright (c) 1980 Regents of the University of California.\n\
1019907Sdist  All rights reserved.\n";
1119907Sdist #endif not lint
1219907Sdist 
1319907Sdist #ifndef lint
14*25791Skarels static char sccsid[] = "@(#)stty.c	5.3 (Berkeley) 01/09/86";
1519907Sdist #endif not lint
1619907Sdist 
171179Sbill /*
181179Sbill  * set teletype modes
191179Sbill  */
201179Sbill 
211179Sbill #include <stdio.h>
2218023Sbloom #include <sys/ioctl.h>
231179Sbill 
2413073Ssam struct
2513073Ssam {
261179Sbill 	char	*string;
271179Sbill 	int	speed;
281179Sbill } speeds[] = {
2913073Ssam 	"0",	B0,
3013073Ssam 	"50",	B50,
3113073Ssam 	"75",	B75,
3213073Ssam 	"110",	B110,
3313073Ssam 	"134",	B134,
3413073Ssam 	"134.5",B134,
3513073Ssam 	"150",	B150,
3613073Ssam 	"200",	B200,
3713073Ssam 	"300",	B300,
3813073Ssam 	"600",	B600,
3913073Ssam 	"1200",	B1200,
4013073Ssam 	"1800",	B1800,
4113073Ssam 	"2400",	B2400,
4213073Ssam 	"4800",	B4800,
4313073Ssam 	"9600",	B9600,
4413073Ssam 	"exta",	EXTA,
4513073Ssam 	"19200", EXTA,
4613073Ssam 	"extb",	EXTB,
4713073Ssam 	"38400", EXTB,
4813073Ssam 	0,
491179Sbill };
5013073Ssam struct
5113073Ssam {
521179Sbill 	char	*string;
5313073Ssam 	int	set;
5413073Ssam 	int	reset;
5513073Ssam 	int	lset;
5613073Ssam 	int	lreset;
571179Sbill } modes[] = {
5813073Ssam 	"even",		EVENP, 0, 0, 0,
5913073Ssam 	"-even",	0, EVENP, 0, 0,
6013073Ssam 	"odd",		ODDP, 0, 0, 0,
6113073Ssam 	"-odd",		0, ODDP, 0, 0,
6213073Ssam 	"raw",		RAW, 0, 0, 0,
6313073Ssam 	"-raw",		0, RAW, 0, 0,
6413073Ssam 	"cooked",	0, RAW, 0, 0,
6513073Ssam 	"-nl",		CRMOD, 0, 0, 0,
6613073Ssam 	"nl",		0, CRMOD, 0, 0,
6713073Ssam 	"echo",		ECHO, 0, 0, 0,
6813073Ssam 	"-echo",	0, ECHO, 0, 0,
6913073Ssam 	"LCASE",	LCASE, 0, 0, 0,
7013073Ssam 	"lcase",	LCASE, 0, 0, 0,
7113073Ssam 	"-LCASE",	0, LCASE, 0, 0,
7213073Ssam 	"-lcase",	0, LCASE, 0, 0,
7313073Ssam 	"-tabs",	XTABS, 0, 0, 0,
7413073Ssam 	"tabs",		0, XTABS, 0, 0,
7513073Ssam 	"tandem",	TANDEM, 0, 0, 0,
7613073Ssam 	"-tandem",	0, TANDEM, 0, 0,
7713073Ssam 	"cbreak",	CBREAK, 0, 0, 0,
7813073Ssam 	"-cbreak",	0, CBREAK, 0, 0,
7913073Ssam 	"cr0",		CR0, CR3, 0, 0,
8013073Ssam 	"cr1",		CR1, CR3, 0, 0,
8113073Ssam 	"cr2",		CR2, CR3, 0, 0,
8213073Ssam 	"cr3",		CR3, CR3, 0, 0,
8313073Ssam 	"tab0",		TAB0, XTABS, 0, 0,
8413073Ssam 	"tab1",		TAB1, XTABS, 0, 0,
8513073Ssam 	"tab2",		TAB2, XTABS, 0, 0,
8613073Ssam 	"nl0",		NL0, NL3, 0, 0,
8713073Ssam 	"nl1",		NL1, NL3, 0, 0,
8813073Ssam 	"nl2",		NL2, NL3, 0, 0,
8913073Ssam 	"nl3",		NL3, NL3, 0, 0,
9013073Ssam 	"ff0",		FF0, FF1, 0, 0,
9113073Ssam 	"ff1",		FF1, FF1, 0, 0,
9213073Ssam 	"bs0",		BS0, BS1, 0, 0,
9313073Ssam 	"bs1",		BS1, BS1, 0, 0,
9413073Ssam 	"33",		CR1, ALLDELAY, 0, 0,
9513073Ssam 	"tty33",	CR1, ALLDELAY, 0, 0,
9613073Ssam 	"37",		FF1+CR2+TAB1+NL1, ALLDELAY, 0, 0,
9713073Ssam 	"tty37",	FF1+CR2+TAB1+NL1, ALLDELAY, 0, 0,
9813073Ssam 	"05",		NL2, ALLDELAY, 0, 0,
9913073Ssam 	"vt05",		NL2, ALLDELAY, 0, 0,
10013073Ssam 	"tn",		CR1, ALLDELAY, 0, 0,
10113073Ssam 	"tn300",	CR1, ALLDELAY, 0, 0,
10213073Ssam 	"ti",		CR2, ALLDELAY, 0, 0,
10313073Ssam 	"ti700",	CR2, ALLDELAY, 0, 0,
10413073Ssam 	"tek",		FF1, ALLDELAY, 0, 0,
10513073Ssam 	"crtbs",	0, 0, LCRTBS, LPRTERA,
10613073Ssam 	"-crtbs",	0, 0, 0, LCRTBS,
10713073Ssam 	"prterase",	0, 0, LPRTERA, LCRTBS+LCRTKIL+LCRTERA,
10813073Ssam 	"-prterase",	0, 0, 0, LPRTERA,
10913073Ssam 	"crterase",	0, 0, LCRTERA, LPRTERA,
11013073Ssam 	"-crterase",	0, 0, 0, LCRTERA,
11113073Ssam 	"crtkill",	0, 0, LCRTKIL, LPRTERA,
11213073Ssam 	"-crtkill",	0, 0, 0, LCRTKIL,
11313073Ssam 	"tilde",	0, 0, LTILDE, 0,
11413073Ssam 	"-tilde",	0, 0, 0, LTILDE,
11513073Ssam 	"mdmbuf",	0, 0, LMDMBUF, 0,
11613073Ssam 	"-mdmbuf",	0, 0, 0, LMDMBUF,
11713073Ssam 	"litout",	0, 0, LLITOUT, 0,
11813073Ssam 	"-litout",	0, 0, 0, LLITOUT,
11924277Slepreau 	"pass8",	0, 0, LPASS8, 0,
12024277Slepreau 	"-pass8",	0, 0, 0, LPASS8,
12113073Ssam 	"tostop",	0, 0, LTOSTOP, 0,
12213073Ssam 	"-tostop",	0, 0, 0, LTOSTOP,
12313073Ssam 	"flusho",	0, 0, LFLUSHO, 0,
12413073Ssam 	"-flusho",	0, 0, 0, LFLUSHO,
12513073Ssam 	"nohang",	0, 0, LNOHANG, 0,
12613073Ssam 	"-nohang",	0, 0, 0, LNOHANG,
1279853Ssam #ifdef notdef
12813073Ssam 	"etxack",	0, 0, LETXACK, 0,
12913073Ssam 	"-etxack",	0, 0, 0, LETXACK,
1309853Ssam #endif
13113073Ssam 	"ctlecho",	0, 0, LCTLECH, 0,
13213073Ssam 	"-ctlecho",	0, 0, 0, LCTLECH,
13313073Ssam 	"pendin",	0, 0, LPENDIN, 0,
13413073Ssam 	"-pendin",	0, 0, 0, LPENDIN,
13513073Ssam 	"decctlq",	0, 0, LDECCTQ, 0,
13613073Ssam 	"-decctlq",	0, 0, 0, LDECCTQ,
13713073Ssam 	"noflsh",	0, 0, LNOFLSH, 0,
13813073Ssam 	"-noflsh",	0, 0, 0, LNOFLSH,
13913073Ssam 	0,
1401179Sbill };
1411179Sbill 
14213073Ssam struct tchars tc;
14313073Ssam struct ltchars ltc;
14413073Ssam struct sgttyb mode;
14518023Sbloom struct winsize win;
14613073Ssam int	lmode;
1471179Sbill int	oldisc, ldisc;
1481179Sbill 
1491179Sbill struct	special {
1501179Sbill 	char	*name;
1511179Sbill 	char	*cp;
1521179Sbill 	char	def;
1531179Sbill } special[] = {
15413073Ssam 	"erase",	&mode.sg_erase,		CERASE,
15513073Ssam 	"kill",		&mode.sg_kill,		CKILL,
15613073Ssam 	"intr",		&tc.t_intrc,		CINTR,
15713073Ssam 	"quit",		&tc.t_quitc,		CQUIT,
15813073Ssam 	"start",	&tc.t_startc,		CSTART,
15913073Ssam 	"stop",		&tc.t_stopc,		CSTOP,
16013073Ssam 	"eof",		&tc.t_eofc,		CEOF,
16113073Ssam 	"brk",		&tc.t_brkc,		CBRK,
16213073Ssam 	"susp",		&ltc.t_suspc,		CSUSP,
16313073Ssam 	"dsusp",	&ltc.t_dsuspc,		CDSUSP,
16413073Ssam 	"rprnt",	&ltc.t_rprntc,		CRPRNT,
16513073Ssam 	"flush",	&ltc.t_flushc,		CFLUSH,
16613073Ssam 	"werase",	&ltc.t_werasc,		CWERASE,
16713073Ssam 	"lnext",	&ltc.t_lnextc,		CLNEXT,
1681179Sbill 	0
1691179Sbill };
1701179Sbill char	*arg;
1711179Sbill 
1721179Sbill int	argc;
1731179Sbill char	**argv;
1741179Sbill main(iargc, iargv)
17513073Ssam char	**iargv;
1761179Sbill {
1771179Sbill 	int i;
1781179Sbill 	register struct special *sp;
1791179Sbill 	char obuf[BUFSIZ];
1801179Sbill 
1811179Sbill 	setbuf(stderr, obuf);
1821179Sbill 	argc = iargc;
1831179Sbill 	argv = iargv;
18413073Ssam 	ioctl(1, TIOCGETP, &mode);
1851179Sbill 	ioctl(1, TIOCGETD, &ldisc);
1861179Sbill 	oldisc = ldisc;
18713073Ssam 	ioctl(1, TIOCGETC, &tc);
18813073Ssam 	ioctl(1, TIOCLGET, &lmode);
18913073Ssam 	ioctl(1, TIOCGLTC, &ltc);
19018023Sbloom 	ioctl(1, TIOCGWINSZ, &win);
19113073Ssam 	if(argc == 1) {
1921179Sbill 		prmodes(0);
1931179Sbill 		exit(0);
1941179Sbill 	}
1951179Sbill 	if (argc == 2 && !strcmp(argv[1], "all")) {
1961179Sbill 		prmodes(1);
1971179Sbill 		exit(0);
1981179Sbill 	}
1991179Sbill 	if (argc == 2 && !strcmp(argv[1], "everything")) {
2001179Sbill 		prmodes(2);
2011179Sbill 		exit(0);
2021179Sbill 	}
20313073Ssam /*
20413073Ssam 	if (argc == 2 && !strcmp(argv[1], "all")) {
20513073Ssam 		prmodes(2);
20613073Ssam 		exit(0);
20713073Ssam 	}
20813073Ssam */
20913073Ssam 	while(--argc > 0) {
2101179Sbill 		arg = *++argv;
21113073Ssam 		if (eq("ek")){
21213073Ssam 			mode.sg_erase = '#';
21313073Ssam 			mode.sg_kill = '@';
2141179Sbill 			continue;
2151179Sbill 		}
21613073Ssam 		if (eq("new")){
2171179Sbill 			ldisc = NTTYDISC;
21813073Ssam 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2191179Sbill 				perror("ioctl");
2201179Sbill 			continue;
2211179Sbill 		}
22213073Ssam 		if (eq("newcrt")){
2231179Sbill 			ldisc = NTTYDISC;
22413073Ssam 			lmode &= ~LPRTERA;
22513073Ssam 			lmode |= LCRTBS|LCTLECH;
22613073Ssam 			if (mode.sg_ospeed >= B1200)
22713073Ssam 				lmode |= LCRTERA|LCRTKIL;
22813073Ssam 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2291179Sbill 				perror("ioctl");
2301179Sbill 			continue;
2311179Sbill 		}
23213073Ssam 		if (eq("crt")){
23313073Ssam 			lmode &= ~LPRTERA;
23413073Ssam 			lmode |= LCRTBS|LCTLECH;
23513073Ssam 			if (mode.sg_ospeed >= B1200)
23613073Ssam 				lmode |= LCRTERA|LCRTKIL;
2371179Sbill 			continue;
2381179Sbill 		}
23913073Ssam 		if (eq("old")){
24013073Ssam 			ldisc = 0;
24113073Ssam 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2421179Sbill 				perror("ioctl");
2431179Sbill 			continue;
2441179Sbill 		}
24513073Ssam 		if (eq("dec")){
24613073Ssam 			mode.sg_erase = 0177;
24713073Ssam 			mode.sg_kill = CTRL(u);
24813073Ssam 			tc.t_intrc = CTRL(c);
2493797Sroot 			ldisc = NTTYDISC;
25013073Ssam 			lmode &= ~LPRTERA;
25113073Ssam 			lmode |= LCRTBS|LCTLECH|LDECCTQ;
25213073Ssam 			if (mode.sg_ospeed >= B1200)
25313073Ssam 				lmode |= LCRTERA|LCRTKIL;
25413073Ssam 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2553797Sroot 				perror("ioctl");
2563797Sroot 			continue;
2573797Sroot 		}
2581179Sbill 		for (sp = special; sp->name; sp++)
2591179Sbill 			if (eq(sp->name)) {
2601179Sbill 				if (--argc == 0)
2611179Sbill 					goto done;
2621179Sbill 				if (**++argv == 'u')
2631179Sbill 					*sp->cp = 0377;
2641179Sbill 				else if (**argv == '^')
2653955Sroot 					*sp->cp = ((*argv)[1] == '?') ?
2661179Sbill 					    0177 : (*argv)[1] & 037;
2671179Sbill 				else
2681179Sbill 					*sp->cp = **argv;
2691179Sbill 				goto cont;
2701179Sbill 			}
2711179Sbill 		if (eq("gspeed")) {
27213073Ssam 			mode.sg_ispeed = B300;
27313073Ssam 			mode.sg_ospeed = B9600;
2741179Sbill 			continue;
2751179Sbill 		}
2761179Sbill 		if (eq("hup")) {
27713073Ssam 			ioctl(1, TIOCHPCL, NULL);
2781179Sbill 			continue;
2791179Sbill 		}
28018023Sbloom 		if (eq("rows")) {
28118023Sbloom 			if (--argc == 0)
28218023Sbloom 				goto done;
28318023Sbloom 			win.ws_row = atoi(*++argv);
28418023Sbloom 		}
28518023Sbloom 		if (eq("columns")) {
28618023Sbloom 			if (--argc == 0)
28718023Sbloom 				goto done;
28818023Sbloom 			win.ws_col = atoi(*++argv);
28918023Sbloom 		}
290*25791Skarels 		if (eq("size")) {
291*25791Skarels 			ioctl(open("/dev/tty", 0), TIOCGWINSZ, &win);
292*25791Skarels 			printf("%d %d\n", win.ws_row, win.ws_col);
293*25791Skarels 			exit(0);
294*25791Skarels 		}
29513073Ssam 		for(i=0; speeds[i].string; i++)
29613073Ssam 			if(eq(speeds[i].string)) {
29713073Ssam 				mode.sg_ispeed = mode.sg_ospeed = speeds[i].speed;
2981179Sbill 				goto cont;
2991179Sbill 			}
3001179Sbill 		if (eq("speed")) {
30113073Ssam 			ioctl(open("/dev/tty", 0), TIOCGETP, &mode);
30213073Ssam 			for(i=0; speeds[i].string; i++)
30313073Ssam 				if (mode.sg_ospeed == speeds[i].speed) {
3041179Sbill 					printf("%s\n", speeds[i].string);
3051179Sbill 					exit(0);
3061179Sbill 				}
3071179Sbill 			printf("unknown\n");
3081179Sbill 			exit(1);
3091179Sbill 		}
31013073Ssam 		for(i=0; modes[i].string; i++)
31113073Ssam 			if(eq(modes[i].string)) {
31213073Ssam 				mode.sg_flags &= ~modes[i].reset;
31313073Ssam 				mode.sg_flags |= modes[i].set;
31413073Ssam 				lmode &= ~modes[i].lreset;
31513073Ssam 				lmode |= modes[i].lset;
3161179Sbill 			}
31713073Ssam 		if(arg)
3181179Sbill 			fprintf(stderr,"unknown mode: %s\n", arg);
3191179Sbill cont:
3201179Sbill 		;
3211179Sbill 	}
3221179Sbill done:
32313073Ssam 	ioctl(1, TIOCSETN, &mode);
32413073Ssam 	ioctl(1, TIOCSETC, &tc);
32513073Ssam 	ioctl(1, TIOCSLTC, &ltc);
32613073Ssam 	ioctl(1, TIOCLSET, &lmode);
32718023Sbloom 	ioctl(1, TIOCSWINSZ, &win);
3281179Sbill }
3291179Sbill 
3301179Sbill eq(string)
33113073Ssam char *string;
3321179Sbill {
3331179Sbill 	int i;
3341179Sbill 
33513073Ssam 	if(!arg)
33613073Ssam 		return(0);
3371179Sbill 	i = 0;
3381179Sbill loop:
33913073Ssam 	if(arg[i] != string[i])
3401179Sbill 		return(0);
34113073Ssam 	if(arg[i++] != '\0')
3421179Sbill 		goto loop;
3431179Sbill 	arg = 0;
34413073Ssam 	return(1);
3451179Sbill }
3461179Sbill 
3471179Sbill prmodes(all)
3481179Sbill {
3491179Sbill 	register m;
3501179Sbill 	int any;
3511179Sbill 
35213073Ssam 	if(ldisc==NETLDISC)
3531179Sbill 		fprintf(stderr, "net discipline, ");
35413073Ssam 	else if(ldisc==NTTYDISC)
3551179Sbill 		fprintf(stderr, "new tty, ");
35613073Ssam 	else if(all==2)
3571179Sbill 		fprintf(stderr, "old tty, ");
35813073Ssam 	if(mode.sg_ispeed != mode.sg_ospeed) {
35913073Ssam 		prspeed("input speed ", mode.sg_ispeed);
36013073Ssam 		prspeed("output speed ", mode.sg_ospeed);
3611179Sbill 	} else
36213073Ssam 		prspeed("speed ", mode.sg_ispeed);
36318023Sbloom 	if (all)
36418023Sbloom 		fprintf(stderr, ", %d rows, %d columns", win.ws_row, win.ws_col);
36513073Ssam 	fprintf(stderr, all==2 ? "\n" : "; ");
36613073Ssam 	m = mode.sg_flags;
36713073Ssam 	if(all==2 || (m&(EVENP|ODDP))!=(EVENP|ODDP)) {
36813073Ssam 		if(m & EVENP)	fprintf(stderr,"even ");
36913073Ssam 		if(m & ODDP)	fprintf(stderr,"odd ");
3701179Sbill 	}
37113073Ssam 	if(all==2 || m&RAW)
37213073Ssam 		fprintf(stderr,"-raw "+((m&RAW)!=0));
37313073Ssam 	if(all==2 || (m&CRMOD)==0)
37413073Ssam 		fprintf(stderr,"-nl "+((m&CRMOD)==0));
37513073Ssam 	if(all==2 || (m&ECHO)==0)
37613073Ssam 		fprintf(stderr,"-echo "+((m&ECHO)!=0));
37713073Ssam 	if(all==2 || (m&LCASE))
37813073Ssam 		fprintf(stderr,"-lcase "+((m&LCASE)!=0));
37913073Ssam 	if(all==2 || (m&TANDEM))
38013073Ssam 		fprintf(stderr,"-tandem "+((m&TANDEM)!=0));
38113073Ssam 	fprintf(stderr,"-tabs "+((m&XTABS)!=XTABS));
38213073Ssam 	if(all==2 || (m&CBREAK))
38313073Ssam 		fprintf(stderr,"-cbreak "+((m&CBREAK)!=0));
38413073Ssam 	if(all==2 || (m&NLDELAY))
38513073Ssam 		delay((m&NLDELAY)/NL1,	"nl");
38613073Ssam 	if ((m&TBDELAY)!=XTABS)
38713073Ssam 		delay((m&TBDELAY)/TAB1,	"tab");
38813073Ssam 	if(all==2 || (m&CRDELAY))
38913073Ssam 		delay((m&CRDELAY)/CR1,	"cr");
39013073Ssam 	if(all==2 || (m&VTDELAY))
39113073Ssam 		delay((m&VTDELAY)/FF1,	"ff");
39213073Ssam 	if(all==2 || (m&BSDELAY))
39313073Ssam 		delay((m&BSDELAY)/BS1,	"bs");
3941179Sbill 	if (all)
3951179Sbill 		fprintf(stderr,"\n");
3961179Sbill #define	lpit(what,str) \
39713073Ssam 	if (all==2||(lmode&what)) { \
39813073Ssam 		fprintf(stderr,str+((lmode&what)!=0)); any++; \
3991179Sbill 	}
4001179Sbill 	if (ldisc == NTTYDISC) {
40113073Ssam 		int newcrt = (lmode&(LCTLECH|LCRTBS)) == (LCTLECH|LCRTBS) &&
40213073Ssam 		    (lmode&(LCRTERA|LCRTKIL)) ==
40313073Ssam 		      ((mode.sg_ospeed > B300) ? LCRTERA|LCRTKIL : 0);
40413817Ssam 		int nothing = 1;
4051179Sbill 		if (newcrt) {
40613073Ssam 			if (all==2)
40713073Ssam 				fprintf(stderr, "crt: (crtbs crterase crtkill ctlecho) ");
40813073Ssam 			else
40913073Ssam 				fprintf(stderr, "crt ");
4101179Sbill 			any++;
4111179Sbill 		} else {
41213073Ssam 			lpit(LCRTBS, "-crtbs ");
41313073Ssam 			lpit(LCRTERA, "-crterase ");
41413073Ssam 			lpit(LCRTKIL, "-crtkill ");
41513073Ssam 			lpit(LCTLECH, "-ctlecho ");
41613073Ssam 			lpit(LPRTERA, "-prterase ");
4171179Sbill 		}
41813073Ssam 		lpit(LTOSTOP, "-tostop ");
41913073Ssam 		if (all==2) {
4201179Sbill 			fprintf(stderr, "\n");
4211179Sbill 			any = 0;
42213817Ssam 			nothing = 0;
4231179Sbill 		}
42413073Ssam 		lpit(LTILDE, "-tilde ");
42513073Ssam 		lpit(LFLUSHO, "-flusho ");
42613073Ssam 		lpit(LMDMBUF, "-mdmbuf ");
42713073Ssam 		lpit(LLITOUT, "-litout ");
42824277Slepreau 		lpit(LPASS8, "-pass8 ");
42913073Ssam 		lpit(LNOHANG, "-nohang ");
4304017Sroot 		if (any) {
4314017Sroot 			fprintf(stderr,"\n");
4324017Sroot 			any = 0;
43313817Ssam 			nothing = 0;
4344017Sroot 		}
4359853Ssam #ifdef notdef
43613073Ssam 		lpit(LETXACK, "-etxack ");
4379853Ssam #endif
43813073Ssam 		lpit(LPENDIN, "-pendin ");
43913073Ssam 		lpit(LDECCTQ, "-decctlq ");
44013073Ssam 		lpit(LNOFLSH, "-noflsh ");
44113817Ssam 		if (any || nothing)
4421179Sbill 			fprintf(stderr,"\n");
4431179Sbill 	} else if (!all)
4441179Sbill 		fprintf(stderr,"\n");
4451179Sbill 	if (all) {
4461179Sbill 		switch (ldisc) {
4471179Sbill 
4481179Sbill 		case 0:
4491179Sbill 			fprintf(stderr,"\
4501179Sbill erase  kill   intr   quit   stop   eof\
4511179Sbill \n");
45213073Ssam 			pcol(mode.sg_erase, -1);
45313073Ssam 			pcol(mode.sg_kill, -1);
45413073Ssam 			pcol(tc.t_intrc, -1);
45513073Ssam 			pcol(tc.t_quitc, -1);
45613073Ssam 			pcol(tc.t_stopc, tc.t_startc);
45713073Ssam 			pcol(tc.t_eofc, tc.t_brkc);
4581179Sbill 			fprintf(stderr,"\n");
4591179Sbill 			break;
4601179Sbill 
4611179Sbill 		case NTTYDISC:
4621179Sbill 			fprintf(stderr,"\
4631179Sbill erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof\
4641179Sbill \n");
46513073Ssam 			pcol(mode.sg_erase, -1);
46613073Ssam 			pcol(mode.sg_kill, -1);
46713073Ssam 			pcol(ltc.t_werasc, -1);
46813073Ssam 			pcol(ltc.t_rprntc, -1);
46913073Ssam 			pcol(ltc.t_flushc, -1);
47013073Ssam 			pcol(ltc.t_lnextc, -1);
47113073Ssam 			pcol(ltc.t_suspc, ltc.t_dsuspc);
47213073Ssam 			pcol(tc.t_intrc, -1);
47313073Ssam 			pcol(tc.t_quitc, -1);
47413073Ssam 			pcol(tc.t_stopc, tc.t_startc);
47513073Ssam 			pcol(tc.t_eofc, tc.t_brkc);
4761179Sbill 			fprintf(stderr,"\n");
4771179Sbill 			break;
4781179Sbill 		}
4791179Sbill 	} else if (ldisc != NETLDISC) {
4801179Sbill 		register struct special *sp;
4811179Sbill 		int first = 1;
48213817Ssam 
4831179Sbill 		for (sp = special; sp->name; sp++) {
4841179Sbill 			if ((*sp->cp&0377) != (sp->def&0377)) {
4851179Sbill 				pit(*sp->cp, sp->name, first ? "" : ", ");
4861179Sbill 				first = 0;
4871179Sbill 			};
48813073Ssam 			if (sp->cp == &tc.t_brkc && ldisc == 0)
4891179Sbill 				break;
4901179Sbill 		}
49113817Ssam 		if (!first)
49213073Ssam 			fprintf(stderr, "\n");
4931179Sbill 	}
4941179Sbill }
4951179Sbill 
4961179Sbill pcol(ch1, ch2)
4971179Sbill 	int ch1, ch2;
4981179Sbill {
4991179Sbill 	int nout = 0;
5001179Sbill 
5011179Sbill 	ch1 &= 0377;
5021179Sbill 	ch2 &= 0377;
5031179Sbill 	if (ch1 == ch2)
5041179Sbill 		ch2 = 0377;
5051179Sbill 	for (; ch1 != 0377 || ch2 != 0377; ch1 = ch2, ch2 = 0377) {
5061179Sbill 		if (ch1 == 0377)
5071179Sbill 			continue;
5081179Sbill 		if (ch1 & 0200) {
5091179Sbill 			fprintf(stderr, "M-");
5101179Sbill 			nout += 2;
5111179Sbill 			ch1 &= ~ 0200;
5121179Sbill 		}
5131179Sbill 		if (ch1 == 0177) {
5141179Sbill 			fprintf(stderr, "^");
5151179Sbill 			nout++;
5161179Sbill 			ch1 = '?';
5171179Sbill 		} else if (ch1 < ' ') {
5181179Sbill 			fprintf(stderr, "^");
5191179Sbill 			nout++;
5201179Sbill 			ch1 += '@';
5211179Sbill 		}
5221179Sbill 		fprintf(stderr, "%c", ch1);
5231179Sbill 		nout++;
5241179Sbill 		if (ch2 != 0377) {
5251179Sbill 			fprintf(stderr, "/");
5261179Sbill 			nout++;
5271179Sbill 		}
5281179Sbill 	}
5291179Sbill 	while (nout < 7) {
5301179Sbill 		fprintf(stderr, " ");
5311179Sbill 		nout++;
5321179Sbill 	}
5331179Sbill }
5341179Sbill 
5351179Sbill pit(what, itsname, sep)
5361179Sbill 	unsigned what;
5371179Sbill 	char *itsname, *sep;
5381179Sbill {
5391179Sbill 
5401179Sbill 	what &= 0377;
5411179Sbill 	fprintf(stderr, "%s%s", sep, itsname);
5421179Sbill 	if (what == 0377) {
5431179Sbill 		fprintf(stderr, " <undef>");
5441179Sbill 		return;
5451179Sbill 	}
5461179Sbill 	fprintf(stderr, " = ");
5471179Sbill 	if (what & 0200) {
5481179Sbill 		fprintf(stderr, "M-");
5491179Sbill 		what &= ~ 0200;
5501179Sbill 	}
5511179Sbill 	if (what == 0177) {
5521179Sbill 		fprintf(stderr, "^");
5531179Sbill 		what = '?';
5541179Sbill 	} else if (what < ' ') {
5551179Sbill 		fprintf(stderr, "^");
5561179Sbill 		what += '@';
5571179Sbill 	}
5581179Sbill 	fprintf(stderr, "%c", what);
5591179Sbill }
5601179Sbill 
5611179Sbill delay(m, s)
56213073Ssam char *s;
5631179Sbill {
5641179Sbill 
56513073Ssam 	if(m)
5661179Sbill 		fprintf(stderr,"%s%d ", s, m);
5671179Sbill }
5681179Sbill 
5691179Sbill int	speed[] = {
5706815Swnj 	0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400
5711179Sbill };
5721179Sbill 
5731179Sbill prspeed(c, s)
5741179Sbill char *c;
5751179Sbill {
5761179Sbill 
5771179Sbill 	fprintf(stderr,"%s%d baud",  c, speed[s]);
5781179Sbill }
579