xref: /csrg-svn/bin/stty/stty.c (revision 9853)
1*9853Ssam static char *sccsid ="@(#)stty.c	4.10 (Berkeley) 12/19/82";
21179Sbill /*
31179Sbill  * set teletype modes
41179Sbill  */
51179Sbill 
61179Sbill #include <stdio.h>
71179Sbill #include <sgtty.h>
81179Sbill 
9*9853Ssam struct {
101179Sbill 	char	*string;
111179Sbill 	int	speed;
121179Sbill } speeds[] = {
13*9853Ssam 	{ "0",		B0 },
14*9853Ssam 	{ "50",		B50 },
15*9853Ssam 	{ "75",		B75 },
16*9853Ssam 	{ "110",	B110 },
17*9853Ssam 	{ "134",	B134 },
18*9853Ssam 	{ "134.5",	B134 },
19*9853Ssam 	{ "150",	B150 },
20*9853Ssam 	{ "200",	B200 },
21*9853Ssam 	{ "300",	B300 },
22*9853Ssam 	{ "600",	B600 },
23*9853Ssam 	{ "1200",	B1200 },
24*9853Ssam 	{ "1800",	B1800 },
25*9853Ssam 	{ "2400",	B2400 },
26*9853Ssam 	{ "4800",	B4800 },
27*9853Ssam 	{ "9600",	B9600 },
28*9853Ssam 	{ "exta",	EXTA },
29*9853Ssam 	{ "19200",	EXTA },
30*9853Ssam 	{ "extb",	EXTB },
31*9853Ssam 	{ "38400",	EXTB },
32*9853Ssam 	{ 0 },
331179Sbill };
34*9853Ssam 
35*9853Ssam struct {
361179Sbill 	char	*string;
37*9853Ssam 	long	set;
38*9853Ssam 	long	reset;
391179Sbill } modes[] = {
40*9853Ssam 	{ "even",	EVENP,		0 },
41*9853Ssam 	{ "-even",	0,		EVENP },
42*9853Ssam 	{ "odd",	ODDP,		0 },
43*9853Ssam 	{ "-odd",	0,		ODDP },
44*9853Ssam 	{ "raw",	RAW,		0 },
45*9853Ssam 	{ "-raw",	0,		RAW },
46*9853Ssam 	{ "cooked",	0,		RAW },
47*9853Ssam 	{ "-nl",	CRMOD,		0 },
48*9853Ssam 	{ "nl",		0,		CRMOD },
49*9853Ssam 	{ "echo",	ECHO,		0 },
50*9853Ssam 	{ "-echo",	0,		ECHO },
51*9853Ssam 	{ "LCASE",	LCASE,		0 },
52*9853Ssam 	{ "lcase",	LCASE,		0 },
53*9853Ssam 	{ "-LCASE",	0,		LCASE },
54*9853Ssam 	{ "-lcase",	0,		LCASE },
55*9853Ssam 	{ "-tabs",	XTABS,		0 },
56*9853Ssam 	{ "tabs",	0,		XTABS },
57*9853Ssam 	{ "tandem",	TANDEM,		0 },
58*9853Ssam 	{ "-tandem",	0,		TANDEM },
59*9853Ssam 	{ "cbreak",	CBREAK,		0 },
60*9853Ssam 	{ "-cbreak",	0,		CBREAK },
61*9853Ssam 	{ "cr0",	CR0,		CR3 },
62*9853Ssam 	{ "cr1",	CR1,		CR3 },
63*9853Ssam 	{ "cr2",	CR2,		CR3 },
64*9853Ssam 	{ "cr3",	CR3,		CR3 },
65*9853Ssam 	{ "tab0",	TAB0,		XTABS },
66*9853Ssam 	{ "tab1",	TAB1,		XTABS },
67*9853Ssam 	{ "tab2",	TAB2,		XTABS },
68*9853Ssam 	{ "nl0",	NL0,		NL3 },
69*9853Ssam 	{ "nl1",	NL1,		NL3 },
70*9853Ssam 	{ "nl2",	NL2,		NL3 },
71*9853Ssam 	{ "nl3",	NL3,		NL3 },
72*9853Ssam 	{ "ff0",	FF0,		FF1 },
73*9853Ssam 	{ "ff1",	FF1,		FF1 },
74*9853Ssam 	{ "bs0",	BS0,		BS1 },
75*9853Ssam 	{ "bs1",	BS1,		BS1 },
76*9853Ssam 	{ "33",		CR1,		ALLDELAY },
77*9853Ssam 	{ "tty33",	CR1,		ALLDELAY },
78*9853Ssam 	{ "37",		FF1+CR2+TAB1+NL1, ALLDELAY },
79*9853Ssam 	{ "tty37",	FF1+CR2+TAB1+NL1, ALLDELAY },
80*9853Ssam 	{ "05",		NL2,		ALLDELAY },
81*9853Ssam 	{ "vt05",	NL2,		ALLDELAY },
82*9853Ssam 	{ "tn",		CR1,		ALLDELAY },
83*9853Ssam 	{ "tn300",	CR1,		ALLDELAY },
84*9853Ssam 	{ "ti",		CR2,		ALLDELAY },
85*9853Ssam 	{ "ti700",	CR2,		ALLDELAY },
86*9853Ssam 	{ "tek",	FF1,		ALLDELAY },
87*9853Ssam 	{ "crtbs",	CRTBS,		PRTERA },
88*9853Ssam 	{ "-crtbs",	0,		CRTBS },
89*9853Ssam 	{ "prterase",	PRTERA,		CRTBS+CRTKIL+CRTERA },
90*9853Ssam 	{ "-prterase",	0,		PRTERA },
91*9853Ssam 	{ "crterase",	CRTERA,		PRTERA },
92*9853Ssam 	{ "-crterase",	0,		CRTERA },
93*9853Ssam 	{ "crtkill",	CRTKIL,		PRTERA },
94*9853Ssam 	{ "-crtkill",	0,		CRTKIL },
95*9853Ssam 	{ "tilde",	TILDE,		0 },
96*9853Ssam 	{ "-tilde",	0,		TILDE },
97*9853Ssam 	{ "mdmbuf",	MDMBUF,		0 },
98*9853Ssam 	{ "-mdmbuf",	0,		MDMBUF },
99*9853Ssam 	{ "litout",	LITOUT,		0 },
100*9853Ssam 	{ "-litout",	0,		LITOUT },
101*9853Ssam 	{ "tostop",	TOSTOP,		0 },
102*9853Ssam 	{ "-tostop",	0,		TOSTOP },
103*9853Ssam 	{ "flusho",	FLUSHO,		0 },
104*9853Ssam 	{ "-flusho",	0,		FLUSHO },
105*9853Ssam 	{ "nohang",	NOHANG,		0 },
106*9853Ssam 	{ "-nohang",	0,		NOHANG },
107*9853Ssam #ifdef notdef
108*9853Ssam 	{ "etxack",	ETXACK,		0 },
109*9853Ssam 	{ "-etxack",	0,		ETXACK },
110*9853Ssam #endif
111*9853Ssam 	{ "ctlecho",	CTLECH,		0 },
112*9853Ssam 	{ "-ctlecho",	0,		CTLECH },
113*9853Ssam 	{ "pendin",	PENDIN,		0 },
114*9853Ssam 	{ "-pendin",	0,		PENDIN },
115*9853Ssam 	{ "decctlq",	DECCTQ,		0 },
116*9853Ssam 	{ "-decctlq",	0,		DECCTQ },
117*9853Ssam 	{ "noflsh",	NOFLSH,		0 },
118*9853Ssam 	{ "-noflsh",	0,		NOFLSH },
119*9853Ssam 	{ 0 },
1201179Sbill };
1211179Sbill 
122*9853Ssam struct ttychars tc;
123*9853Ssam struct sgttyb sb;
124*9853Ssam long	flags;
1251179Sbill int	oldisc, ldisc;
1261179Sbill 
1271179Sbill struct	special {
1281179Sbill 	char	*name;
1291179Sbill 	char	*cp;
1301179Sbill 	char	def;
1311179Sbill } special[] = {
132*9853Ssam 	{ "erase",	&tc.tc_erase,		CERASE },
133*9853Ssam 	{ "kill",	&tc.tc_kill,		CKILL },
134*9853Ssam 	{ "intr",	&tc.tc_intrc,		CINTR },
135*9853Ssam 	{ "quit",	&tc.tc_quitc,		CQUIT },
136*9853Ssam 	{ "start",	&tc.tc_startc,		CSTART },
137*9853Ssam 	{ "stop",	&tc.tc_stopc,		CSTOP },
138*9853Ssam 	{ "eof",	&tc.tc_eofc,		CEOF },
139*9853Ssam 	{ "brk",	&tc.tc_brkc,		CBRK },
140*9853Ssam 	{ "susp",	&tc.tc_suspc,		CSUSP },
141*9853Ssam 	{ "dsusp",	&tc.tc_dsuspc,		CDSUSP },
142*9853Ssam 	{ "rprnt",	&tc.tc_rprntc,		CRPRNT },
143*9853Ssam 	{ "flush",	&tc.tc_flushc,		CFLUSH },
144*9853Ssam 	{ "werase",	&tc.tc_werasc,		CWERASE },
145*9853Ssam 	{ "lnext",	&tc.tc_lnextc,		CLNEXT },
1461179Sbill 	0
1471179Sbill };
1481179Sbill char	*arg;
1491179Sbill 
1501179Sbill int	argc;
1511179Sbill char	**argv;
152*9853Ssam 
1531179Sbill main(iargc, iargv)
154*9853Ssam 	int iargc;
155*9853Ssam 	char *iargv[];
1561179Sbill {
1571179Sbill 	int i;
1581179Sbill 	register struct special *sp;
1591179Sbill 	char obuf[BUFSIZ];
1601179Sbill 
1611179Sbill 	setbuf(stderr, obuf);
1621179Sbill 	argc = iargc;
1631179Sbill 	argv = iargv;
164*9853Ssam 	ioctl(1, TIOCCGET, (char *)&tc);
165*9853Ssam 	ioctl(1, TIOCGET, (char *)&flags);
1661179Sbill 	ioctl(1, TIOCGETD, &ldisc);
167*9853Ssam #ifndef notdef
168*9853Ssam 	ioctl(1, TIOCGETP, (char *)&sb);
169*9853Ssam #endif
1701179Sbill 	oldisc = ldisc;
171*9853Ssam 	if (argc == 1) {
1721179Sbill 		prmodes(0);
1731179Sbill 		exit(0);
1741179Sbill 	}
1751179Sbill 	if (argc == 2 && !strcmp(argv[1], "all")) {
1761179Sbill 		prmodes(1);
1771179Sbill 		exit(0);
1781179Sbill 	}
1791179Sbill 	if (argc == 2 && !strcmp(argv[1], "everything")) {
1801179Sbill 		prmodes(2);
1811179Sbill 		exit(0);
1821179Sbill 	}
183*9853Ssam 	while (--argc > 0) {
1841179Sbill 		arg = *++argv;
185*9853Ssam 		if (eq("ek")) {
186*9853Ssam 			tc.tc_erase = '#';
187*9853Ssam 			tc.tc_kill = '@';
1881179Sbill 			continue;
1891179Sbill 		}
190*9853Ssam 		if (eq("new")) {
1911179Sbill 			ldisc = NTTYDISC;
192*9853Ssam 			if (ioctl(1, TIOCSETD, &ldisc) < 0)
1931179Sbill 				perror("ioctl");
1941179Sbill 			continue;
1951179Sbill 		}
196*9853Ssam 		if (eq("newcrt")) {
1971179Sbill 			ldisc = NTTYDISC;
198*9853Ssam 			flags &= ~PRTERA;
199*9853Ssam 			flags |= CRTBS|CTLECH;
200*9853Ssam 			if (sb.sg_ospeed >= B1200)
201*9853Ssam 				flags |= CRTERA|CRTKIL;
202*9853Ssam 			if (ioctl(1, TIOCSETD, &ldisc) < 0)
2031179Sbill 				perror("ioctl");
2041179Sbill 			continue;
2051179Sbill 		}
206*9853Ssam 		if (eq("crt")) {
207*9853Ssam 			flags &= ~PRTERA;
208*9853Ssam 			flags |= CRTBS|CTLECH;
209*9853Ssam 			if (sb.sg_ospeed >= B1200)
210*9853Ssam 				flags |= CRTERA|CRTKIL;
2111179Sbill 			continue;
2121179Sbill 		}
213*9853Ssam 		if (eq("old")) {
214*9853Ssam 			ldisc = OTTYDISC;
215*9853Ssam 			if (ioctl(1, TIOCSETD, &ldisc) < 0)
2161179Sbill 				perror("ioctl");
2171179Sbill 			continue;
2181179Sbill 		}
219*9853Ssam 		if (eq("dec")) {
220*9853Ssam 			tc.tc_erase = 0177;
221*9853Ssam 			tc.tc_kill = CTRL(u);
222*9853Ssam 			tc.tc_intrc = CTRL(c);
2233797Sroot 			ldisc = NTTYDISC;
224*9853Ssam 			flags &= ~PRTERA;
225*9853Ssam 			flags |= CRTBS|CTLECH|DECCTQ;
226*9853Ssam 			if (sb.sg_ospeed >= B1200)
227*9853Ssam 				flags |= CRTERA|CRTKIL;
228*9853Ssam 			if (ioctl(1, TIOCSETD, &ldisc) < 0)
2293797Sroot 				perror("ioctl");
2303797Sroot 			continue;
2313797Sroot 		}
2321179Sbill 		for (sp = special; sp->name; sp++)
2331179Sbill 			if (eq(sp->name)) {
2341179Sbill 				if (--argc == 0)
2351179Sbill 					goto done;
2361179Sbill 				if (**++argv == 'u')
2371179Sbill 					*sp->cp = 0377;
2381179Sbill 				else if (**argv == '^')
2393955Sroot 					*sp->cp = ((*argv)[1] == '?') ?
2401179Sbill 					    0177 : (*argv)[1] & 037;
2411179Sbill 				else
2421179Sbill 					*sp->cp = **argv;
2431179Sbill 				goto cont;
2441179Sbill 			}
2451179Sbill 		if (eq("gspeed")) {
246*9853Ssam 			sb.sg_ispeed = B300;
247*9853Ssam 			sb.sg_ospeed = B9600;
2481179Sbill 			continue;
2491179Sbill 		}
2501179Sbill 		if (eq("hup")) {
251*9853Ssam 			if (ioctl(1, TIOCHPCL, NULL) < 0)
252*9853Ssam 				perror("ioctl");
2531179Sbill 			continue;
2541179Sbill 		}
255*9853Ssam 		for (i = 0; speeds[i].string; i++)
256*9853Ssam 			if (eq(speeds[i].string)) {
257*9853Ssam 				sb.sg_ispeed = sb.sg_ospeed = speeds[i].speed;
2581179Sbill 				goto cont;
2591179Sbill 			}
2601179Sbill 		if (eq("speed")) {
261*9853Ssam 			int fd = open("/dev/tty", 0);
262*9853Ssam 
263*9853Ssam 			if (fd < 0) {
264*9853Ssam 				perror("open");
265*9853Ssam 				exit(1);
266*9853Ssam 			}
267*9853Ssam 			ioctl(fd, TIOCGETP, &sb);
268*9853Ssam 			for (i = 0; speeds[i].string; i++)
269*9853Ssam 				if (sb.sg_ospeed == speeds[i].speed) {
2701179Sbill 					printf("%s\n", speeds[i].string);
2711179Sbill 					exit(0);
2721179Sbill 				}
2731179Sbill 			printf("unknown\n");
2741179Sbill 			exit(1);
2751179Sbill 		}
276*9853Ssam 		for (i = 0; modes[i].string; i++)
277*9853Ssam 			if (eq(modes[i].string)) {
278*9853Ssam 				flags &= ~modes[i].reset;
279*9853Ssam 				flags |= modes[i].set;
2801179Sbill 			}
281*9853Ssam 		if (arg)
2821179Sbill 			fprintf(stderr,"unknown mode: %s\n", arg);
2831179Sbill cont:
2841179Sbill 		;
2851179Sbill 	}
2861179Sbill done:
287*9853Ssam #ifndef notdef
288*9853Ssam 	ioctl(1, TIOCSETN, &sb);
289*9853Ssam #endif
290*9853Ssam 	ioctl(1, TIOCSET, &flags);
291*9853Ssam 	ioctl(1, TIOCCSET, &tc);
2921179Sbill }
2931179Sbill 
2941179Sbill eq(string)
295*9853Ssam 	char *string;
2961179Sbill {
2971179Sbill 	int i;
2981179Sbill 
299*9853Ssam 	if (!arg)
300*9853Ssam 		return (0);
3011179Sbill 	i = 0;
3021179Sbill loop:
303*9853Ssam 	if (arg[i] != string[i])
3041179Sbill 		return(0);
305*9853Ssam 	if (arg[i++] != '\0')
3061179Sbill 		goto loop;
3071179Sbill 	arg = 0;
308*9853Ssam 	return (1);
3091179Sbill }
3101179Sbill 
3111179Sbill prmodes(all)
312*9853Ssam 	int all;
3131179Sbill {
3141179Sbill 	register m;
3151179Sbill 	int any;
3161179Sbill 
317*9853Ssam 	if (ldisc == NETLDISC)
3181179Sbill 		fprintf(stderr, "net discipline, ");
319*9853Ssam 	else if (ldisc == NTTYDISC)
3201179Sbill 		fprintf(stderr, "new tty, ");
321*9853Ssam 	else if (all == 2)
3221179Sbill 		fprintf(stderr, "old tty, ");
323*9853Ssam 	if(sb.sg_ispeed != sb.sg_ospeed) {
324*9853Ssam 		prspeed("input speed ", sb.sg_ispeed);
325*9853Ssam 		prspeed("output speed ", sb.sg_ospeed);
3261179Sbill 	} else
327*9853Ssam 		prspeed("speed ", sb.sg_ispeed);
328*9853Ssam 	fprintf(stderr, all == 2 ? "\n" : "; ");
329*9853Ssam 	m = flags;
330*9853Ssam 	if (all == 2 || (m&(EVENP|ODDP)) != (EVENP|ODDP)) {
331*9853Ssam 		if (m & EVENP)
332*9853Ssam 			fprintf(stderr,"even ");
333*9853Ssam 		if (m & ODDP)
334*9853Ssam 			fprintf(stderr,"odd ");
3351179Sbill 	}
336*9853Ssam 	if (all == 2 || m&RAW)
337*9853Ssam 		fprintf(stderr,"-raw " + ((m&RAW) != 0));
338*9853Ssam 	if (all == 2 || (m&CRMOD) == 0)
339*9853Ssam 		fprintf(stderr,"-nl " + ((m&CRMOD) == 0));
340*9853Ssam 	if (all == 2 || (m&ECHO) == 0)
341*9853Ssam 		fprintf(stderr,"-echo " + ((m&ECHO) != 0));
342*9853Ssam 	if (all == 2 || m&LCASE)
343*9853Ssam 		fprintf(stderr,"-lcase " + ((m&LCASE) != 0));
344*9853Ssam 	if (all == 2 || m&TANDEM)
345*9853Ssam 		fprintf(stderr,"-tandem " + ((m&TANDEM) != 0));
346*9853Ssam 	fprintf(stderr,"-tabs " + ((m&XTABS) != XTABS));
347*9853Ssam 	if (all == 2 || m&CBREAK)
348*9853Ssam 		fprintf(stderr,"-cbreak " + ((m&CBREAK) != 0));
349*9853Ssam 	if (all == 2 || m&NLDELAY)
350*9853Ssam 		delay((m&NLDELAY) / NL1, "nl");
351*9853Ssam 	if ((m&TBDELAY) != XTABS)
352*9853Ssam 		delay((m&TBDELAY)/ TAB1, "tab");
353*9853Ssam 	if (all == 2 || m&CRDELAY)
354*9853Ssam 		delay((m&CRDELAY) / CR1, "cr");
355*9853Ssam 	if (all == 2 || m&VTDELAY)
356*9853Ssam 		delay((m&VTDELAY) / FF1, "ff");
357*9853Ssam 	if (all == 2 || m&BSDELAY)
358*9853Ssam 		delay((m&BSDELAY) / BS1, "bs");
3591179Sbill 	if (all)
3601179Sbill 		fprintf(stderr,"\n");
3611179Sbill #define	lpit(what,str) \
362*9853Ssam 	if (all == 2 || flags&what) { \
363*9853Ssam 		fprintf(stderr,str + ((flags&what) != 0)); any++; \
3641179Sbill 	}
3651179Sbill 	if (ldisc == NTTYDISC) {
366*9853Ssam 		int newcrt = (flags&(CTLECH|CRTBS)) == (CTLECH|CRTBS) &&
367*9853Ssam 		    (flags&(CRTERA|CRTKIL)) ==
368*9853Ssam 		      ((sb.sg_ospeed > B300) ? CRTERA|CRTKIL : 0);
3691179Sbill 		if (newcrt) {
370*9853Ssam 			fprintf(stderr, all != 2 ? "crt" :
371*9853Ssam 				 "crt: (crtbs crterase crtkill ctlecho) ");
3721179Sbill 			any++;
3731179Sbill 		} else {
374*9853Ssam 			lpit(CRTBS, "-crtbs ");
375*9853Ssam 			lpit(CRTERA, "-crterase ");
376*9853Ssam 			lpit(CRTKIL, "-crtkill ");
377*9853Ssam 			lpit(CTLECH, "-ctlecho ");
378*9853Ssam 			lpit(PRTERA, "-prterase ");
3791179Sbill 		}
380*9853Ssam 		lpit(TOSTOP, "-tostop ");
381*9853Ssam 		if (all == 2) {
3821179Sbill 			fprintf(stderr, "\n");
3831179Sbill 			any = 0;
3841179Sbill 		}
385*9853Ssam 		lpit(TILDE, "-tilde ");
386*9853Ssam 		lpit(FLUSHO, "-flusho ");
387*9853Ssam 		lpit(MDMBUF, "-mdmbuf ");
388*9853Ssam 		lpit(LITOUT, "-litout ");
389*9853Ssam 		lpit(NOHANG, "-nohang ");
3904017Sroot 		if (any) {
3914017Sroot 			fprintf(stderr,"\n");
3924017Sroot 			any = 0;
3934017Sroot 		}
394*9853Ssam #ifdef notdef
395*9853Ssam 		lpit(ETXACK, "-etxack ");
396*9853Ssam #endif
397*9853Ssam 		lpit(PENDIN, "-pendin ");
398*9853Ssam 		lpit(DECCTQ, "-decctlq ");
399*9853Ssam 		lpit(NOFLSH, "-noflsh ");
4001179Sbill 		if (any)
4011179Sbill 			fprintf(stderr,"\n");
4021179Sbill 	} else if (!all)
4031179Sbill 		fprintf(stderr,"\n");
4041179Sbill 	if (all) {
4051179Sbill 		switch (ldisc) {
4061179Sbill 
4071179Sbill 		case 0:
4081179Sbill 			fprintf(stderr,"\
4091179Sbill erase  kill   intr   quit   stop   eof\
4101179Sbill \n");
411*9853Ssam 			pcol(tc.tc_erase, -1);
412*9853Ssam 			pcol(tc.tc_kill, -1);
413*9853Ssam 			pcol(tc.tc_intrc, -1);
414*9853Ssam 			pcol(tc.tc_quitc, -1);
415*9853Ssam 			pcol(tc.tc_stopc, tc.tc_startc);
416*9853Ssam 			pcol(tc.tc_eofc, tc.tc_brkc);
4171179Sbill 			fprintf(stderr,"\n");
4181179Sbill 			break;
4191179Sbill 
4201179Sbill 		case NTTYDISC:
4211179Sbill 			fprintf(stderr,"\
4221179Sbill erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof\
4231179Sbill \n");
424*9853Ssam 			pcol(tc.tc_erase, -1);
425*9853Ssam 			pcol(tc.tc_kill, -1);
426*9853Ssam 			pcol(tc.tc_werasc, -1);
427*9853Ssam 			pcol(tc.tc_rprntc, -1);
428*9853Ssam 			pcol(tc.tc_flushc, -1);
429*9853Ssam 			pcol(tc.tc_lnextc, -1);
430*9853Ssam 			pcol(tc.tc_suspc, tc.tc_dsuspc);
431*9853Ssam 			pcol(tc.tc_intrc, -1);
432*9853Ssam 			pcol(tc.tc_quitc, -1);
433*9853Ssam 			pcol(tc.tc_stopc, tc.tc_startc);
434*9853Ssam 			pcol(tc.tc_eofc, tc.tc_brkc);
4351179Sbill 			fprintf(stderr,"\n");
4361179Sbill 			break;
4371179Sbill 		}
4381179Sbill 	} else if (ldisc != NETLDISC) {
4391179Sbill 		register struct special *sp;
4401179Sbill 		int first = 1;
441*9853Ssam 
4421179Sbill 		for (sp = special; sp->name; sp++) {
4431179Sbill 			if ((*sp->cp&0377) != (sp->def&0377)) {
4441179Sbill 				pit(*sp->cp, sp->name, first ? "" : ", ");
4451179Sbill 				first = 0;
4461179Sbill 			};
447*9853Ssam 			if (sp->cp == &tc.tc_brkc && ldisc == 0)
4481179Sbill 				break;
4491179Sbill 		}
4501179Sbill 		if (first == 0)
4511179Sbill 			fprintf(stderr, "\n");
4521179Sbill 	}
4531179Sbill }
4541179Sbill 
4551179Sbill pcol(ch1, ch2)
4561179Sbill 	int ch1, ch2;
4571179Sbill {
4581179Sbill 	int nout = 0;
4591179Sbill 
4601179Sbill 	ch1 &= 0377;
4611179Sbill 	ch2 &= 0377;
4621179Sbill 	if (ch1 == ch2)
4631179Sbill 		ch2 = 0377;
4641179Sbill 	for (; ch1 != 0377 || ch2 != 0377; ch1 = ch2, ch2 = 0377) {
4651179Sbill 		if (ch1 == 0377)
4661179Sbill 			continue;
4671179Sbill 		if (ch1 & 0200) {
4681179Sbill 			fprintf(stderr, "M-");
4691179Sbill 			nout += 2;
4701179Sbill 			ch1 &= ~ 0200;
4711179Sbill 		}
4721179Sbill 		if (ch1 == 0177) {
4731179Sbill 			fprintf(stderr, "^");
4741179Sbill 			nout++;
4751179Sbill 			ch1 = '?';
4761179Sbill 		} else if (ch1 < ' ') {
4771179Sbill 			fprintf(stderr, "^");
4781179Sbill 			nout++;
4791179Sbill 			ch1 += '@';
4801179Sbill 		}
4811179Sbill 		fprintf(stderr, "%c", ch1);
4821179Sbill 		nout++;
4831179Sbill 		if (ch2 != 0377) {
4841179Sbill 			fprintf(stderr, "/");
4851179Sbill 			nout++;
4861179Sbill 		}
4871179Sbill 	}
4881179Sbill 	while (nout < 7) {
4891179Sbill 		fprintf(stderr, " ");
4901179Sbill 		nout++;
4911179Sbill 	}
4921179Sbill }
4931179Sbill 
4941179Sbill pit(what, itsname, sep)
4951179Sbill 	unsigned what;
4961179Sbill 	char *itsname, *sep;
4971179Sbill {
4981179Sbill 
4991179Sbill 	what &= 0377;
5001179Sbill 	fprintf(stderr, "%s%s", sep, itsname);
5011179Sbill 	if (what == 0377) {
5021179Sbill 		fprintf(stderr, " <undef>");
5031179Sbill 		return;
5041179Sbill 	}
5051179Sbill 	fprintf(stderr, " = ");
5061179Sbill 	if (what & 0200) {
5071179Sbill 		fprintf(stderr, "M-");
5081179Sbill 		what &= ~ 0200;
5091179Sbill 	}
5101179Sbill 	if (what == 0177) {
5111179Sbill 		fprintf(stderr, "^");
5121179Sbill 		what = '?';
5131179Sbill 	} else if (what < ' ') {
5141179Sbill 		fprintf(stderr, "^");
5151179Sbill 		what += '@';
5161179Sbill 	}
5171179Sbill 	fprintf(stderr, "%c", what);
5181179Sbill }
5191179Sbill 
5201179Sbill delay(m, s)
521*9853Ssam 	char *s;
5221179Sbill {
5231179Sbill 
524*9853Ssam 	if (m)
5251179Sbill 		fprintf(stderr,"%s%d ", s, m);
5261179Sbill }
5271179Sbill 
5281179Sbill int	speed[] = {
5296815Swnj 	0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,19200,38400
5301179Sbill };
5311179Sbill 
5321179Sbill prspeed(c, s)
5331179Sbill char *c;
5341179Sbill {
5351179Sbill 
5361179Sbill 	fprintf(stderr,"%s%d baud",  c, speed[s]);
5371179Sbill }
538