xref: /csrg-svn/bin/stty/stty.c (revision 4017)
1*4017Sroot static char *sccsid ="@(#)stty.c	4.7 (Berkeley) 07/18/81";
21179Sbill /*
31179Sbill  * set teletype modes
41179Sbill  */
51179Sbill 
61179Sbill #include <stdio.h>
71179Sbill #include <sgtty.h>
81179Sbill 
91179Sbill struct
101179Sbill {
111179Sbill 	char	*string;
121179Sbill 	int	speed;
131179Sbill } speeds[] = {
141179Sbill 	"0",	B0,
151179Sbill 	"50",	B50,
161179Sbill 	"75",	B75,
171179Sbill 	"110",	B110,
181179Sbill 	"134",	B134,
191179Sbill 	"134.5",B134,
201179Sbill 	"150",	B150,
211179Sbill 	"200",	B200,
221179Sbill 	"300",	B300,
231179Sbill 	"600",	B600,
241179Sbill 	"1200",	B1200,
251179Sbill 	"1800",	B1800,
261179Sbill 	"2400",	B2400,
271179Sbill 	"4800",	B4800,
281179Sbill 	"9600",	B9600,
291179Sbill 	"exta",	EXTA,
301179Sbill 	"extb",	EXTB,
311179Sbill 	0,
321179Sbill };
331179Sbill struct
341179Sbill {
351179Sbill 	char	*string;
361179Sbill 	int	set;
371179Sbill 	int	reset;
381179Sbill 	int	lset;
391179Sbill 	int	lreset;
401179Sbill } modes[] = {
411179Sbill 	"even",		EVENP, 0, 0, 0,
421179Sbill 	"-even",	0, EVENP, 0, 0,
431179Sbill 	"odd",		ODDP, 0, 0, 0,
441179Sbill 	"-odd",		0, ODDP, 0, 0,
451179Sbill 	"raw",		RAW, 0, 0, 0,
461179Sbill 	"-raw",		0, RAW, 0, 0,
471179Sbill 	"cooked",	0, RAW, 0, 0,
481179Sbill 	"-nl",		CRMOD, 0, 0, 0,
491179Sbill 	"nl",		0, CRMOD, 0, 0,
501179Sbill 	"echo",		ECHO, 0, 0, 0,
511179Sbill 	"-echo",	0, ECHO, 0, 0,
521179Sbill 	"LCASE",	LCASE, 0, 0, 0,
531179Sbill 	"lcase",	LCASE, 0, 0, 0,
541179Sbill 	"-LCASE",	0, LCASE, 0, 0,
551179Sbill 	"-lcase",	0, LCASE, 0, 0,
561179Sbill 	"-tabs",	XTABS, 0, 0, 0,
571179Sbill 	"tabs",		0, XTABS, 0, 0,
581179Sbill 	"tandem",	TANDEM, 0, 0, 0,
591179Sbill 	"-tandem",	0, TANDEM, 0, 0,
601179Sbill 	"cbreak",	CBREAK, 0, 0, 0,
611179Sbill 	"-cbreak",	0, CBREAK, 0, 0,
621179Sbill 	"cr0",		CR0, CR3, 0, 0,
631179Sbill 	"cr1",		CR1, CR3, 0, 0,
641179Sbill 	"cr2",		CR2, CR3, 0, 0,
651179Sbill 	"cr3",		CR3, CR3, 0, 0,
661179Sbill 	"tab0",		TAB0, XTABS, 0, 0,
671179Sbill 	"tab1",		TAB1, XTABS, 0, 0,
681179Sbill 	"tab2",		TAB2, XTABS, 0, 0,
691179Sbill 	"nl0",		NL0, NL3, 0, 0,
701179Sbill 	"nl1",		NL1, NL3, 0, 0,
711179Sbill 	"nl2",		NL2, NL3, 0, 0,
721179Sbill 	"nl3",		NL3, NL3, 0, 0,
731179Sbill 	"ff0",		FF0, FF1, 0, 0,
741179Sbill 	"ff1",		FF1, FF1, 0, 0,
751179Sbill 	"bs0",		BS0, BS1, 0, 0,
761179Sbill 	"bs1",		BS1, BS1, 0, 0,
771179Sbill 	"33",		CR1, ALLDELAY, 0, 0,
781179Sbill 	"tty33",	CR1, ALLDELAY, 0, 0,
791179Sbill 	"37",		FF1+CR2+TAB1+NL1, ALLDELAY, 0, 0,
801179Sbill 	"tty37",	FF1+CR2+TAB1+NL1, ALLDELAY, 0, 0,
811179Sbill 	"05",		NL2, ALLDELAY, 0, 0,
821179Sbill 	"vt05",		NL2, ALLDELAY, 0, 0,
831179Sbill 	"tn",		CR1, ALLDELAY, 0, 0,
841179Sbill 	"tn300",	CR1, ALLDELAY, 0, 0,
851179Sbill 	"ti",		CR2, ALLDELAY, 0, 0,
861179Sbill 	"ti700",	CR2, ALLDELAY, 0, 0,
871179Sbill 	"tek",		FF1, ALLDELAY, 0, 0,
881179Sbill 	"crtbs",	0, 0, LCRTBS, LPRTERA,
891179Sbill 	"-crtbs",	0, 0, 0, LCRTBS,
901179Sbill 	"prterase",	0, 0, LPRTERA, LCRTBS+LCRTKIL+LCRTERA,
911179Sbill 	"-prterase",	0, 0, 0, LPRTERA,
921179Sbill 	"crterase",	0, 0, LCRTERA, LPRTERA,
931179Sbill 	"-crterase",	0, 0, 0, LCRTERA,
941179Sbill 	"crtkill",	0, 0, LCRTKIL, LPRTERA,
951179Sbill 	"-crtkill",	0, 0, 0, LCRTKIL,
961179Sbill 	"tilde",	0, 0, LTILDE, 0,
971179Sbill 	"-tilde",	0, 0, 0, LTILDE,
981179Sbill 	"mdmbuf",	0, 0, LMDMBUF, 0,
991179Sbill 	"-mdmbuf",	0, 0, 0, LMDMBUF,
1001179Sbill 	"litout",	0, 0, LLITOUT, 0,
1011179Sbill 	"-litout",	0, 0, 0, LLITOUT,
1021179Sbill 	"tostop",	0, 0, LTOSTOP, 0,
1031179Sbill 	"-tostop",	0, 0, 0, LTOSTOP,
1041179Sbill 	"flusho",	0, 0, LFLUSHO, 0,
1051179Sbill 	"-flusho",	0, 0, 0, LFLUSHO,
1061179Sbill 	"nohang",	0, 0, LNOHANG, 0,
1071179Sbill 	"-nohang",	0, 0, 0, LNOHANG,
1081179Sbill 	"etxack",	0, 0, LETXACK, 0,
1091179Sbill 	"-etxack",	0, 0, 0, LETXACK,
1101179Sbill 	"intrup",	0, 0, LINTRUP, 0,
1111179Sbill 	"-intrup",	0, 0, 0, LINTRUP,
1121179Sbill 	"ctlecho",	0, 0, LCTLECH, 0,
1131179Sbill 	"-ctlecho",	0, 0, 0, LCTLECH,
1141179Sbill 	"pendin",	0, 0, LPENDIN, 0,
1151179Sbill 	"-pendin",	0, 0, 0, LPENDIN,
1163797Sroot 	"decctlq",	0, 0, LDECCTQ, 0,
1173797Sroot 	"-decctlq",	0, 0, 0, LDECCTQ,
118*4017Sroot 	"noflsh",	0, 0, LNOFLSH, 0,
119*4017Sroot 	"-noflsh",	0, 0, 0, LNOFLSH,
1201179Sbill 	0,
1211179Sbill };
1221179Sbill 
1231179Sbill struct tchars tc;
1241179Sbill struct ltchars ltc;
1251179Sbill struct sgttyb mode;
1261179Sbill int	lmode;
1271179Sbill int	oldisc, ldisc;
1281179Sbill 
1291179Sbill #define	CTRL(x)		('x'&037)
1301179Sbill 
1311179Sbill struct	special {
1321179Sbill 	char	*name;
1331179Sbill 	char	*cp;
1341179Sbill 	char	def;
1351179Sbill } special[] = {
1361179Sbill 	"erase",	&mode.sg_erase,		CTRL(h),
1371179Sbill 	"kill",		&mode.sg_kill,		'@',
1381179Sbill 	"intr",		&tc.t_intrc,		0177,
1391179Sbill 	"quit",		&tc.t_quitc,		CTRL(\\\\),
1401179Sbill 	"start",	&tc.t_startc,		CTRL(q),
1411179Sbill 	"stop",		&tc.t_stopc,		CTRL(s),
1421179Sbill 	"eof",		&tc.t_eofc,		CTRL(d),
1431179Sbill 	"brk",		&tc.t_brkc,		0377,
1441179Sbill 	"susp",		&ltc.t_suspc,		CTRL(z),
1451179Sbill 	"dsusp",	&ltc.t_dsuspc,		CTRL(y),
1461179Sbill 	"rprnt",	&ltc.t_rprntc,		CTRL(r),
1471179Sbill 	"flush",	&ltc.t_flushc,		CTRL(o),
1481179Sbill 	"werase",	&ltc.t_werasc,		CTRL(w),
1491179Sbill 	"lnext",	&ltc.t_lnextc,		CTRL(v),
1501179Sbill 	0
1511179Sbill };
1521179Sbill char	*arg;
1531179Sbill 
1541179Sbill int	argc;
1551179Sbill char	**argv;
1561179Sbill main(iargc, iargv)
1571179Sbill char	**iargv;
1581179Sbill {
1591179Sbill 	int i;
1601179Sbill 	register struct special *sp;
1611179Sbill 	char obuf[BUFSIZ];
1621179Sbill 
1631179Sbill 	setbuf(stderr, obuf);
1641179Sbill 	argc = iargc;
1651179Sbill 	argv = iargv;
1661179Sbill 	gtty(1, &mode);
1671179Sbill 	ioctl(1, TIOCGETD, &ldisc);
1681179Sbill 	oldisc = ldisc;
1691179Sbill 	ioctl(1, TIOCGETC, &tc);
1701179Sbill 	ioctl(1, TIOCLGET, &lmode);
1711179Sbill 	ioctl(1, TIOCGLTC, &ltc);
1721179Sbill 	if(argc == 1) {
1731179Sbill 		prmodes(0);
1741179Sbill 		exit(0);
1751179Sbill 	}
1761179Sbill 	if (argc == 2 && !strcmp(argv[1], "all")) {
1771179Sbill 		prmodes(1);
1781179Sbill 		exit(0);
1791179Sbill 	}
1801179Sbill 	if (argc == 2 && !strcmp(argv[1], "everything")) {
1811179Sbill 		prmodes(2);
1821179Sbill 		exit(0);
1831179Sbill 	}
1841179Sbill /*
1851179Sbill 	if (argc == 2 && !strcmp(argv[1], "all")) {
1861179Sbill 		prmodes(2);
1871179Sbill 		exit(0);
1881179Sbill 	}
1891179Sbill */
1901179Sbill 	while(--argc > 0) {
1911179Sbill 		arg = *++argv;
1921179Sbill 		if (eq("ek")){
1931179Sbill 			mode.sg_erase = '#';
1941179Sbill 			mode.sg_kill = '@';
1951179Sbill 			continue;
1961179Sbill 		}
1971179Sbill 		if (eq("new")){
1981179Sbill 			ldisc = NTTYDISC;
1991179Sbill 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2001179Sbill 				perror("ioctl");
2011179Sbill 			continue;
2021179Sbill 		}
2031179Sbill 		if (eq("newcrt")){
2041179Sbill 			ldisc = NTTYDISC;
2051179Sbill 			lmode &= ~LPRTERA;
2061179Sbill 			lmode |= LCRTBS|LCTLECH;
2071179Sbill 			if (mode.sg_ospeed >= B1200)
2081179Sbill 				lmode |= LCRTERA|LCRTKIL;
2091179Sbill 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2101179Sbill 				perror("ioctl");
2111179Sbill 			continue;
2121179Sbill 		}
2131179Sbill 		if (eq("crt")){
2141179Sbill 			lmode &= ~LPRTERA;
2151179Sbill 			lmode |= LCRTBS|LCTLECH;
2161179Sbill 			if (mode.sg_ospeed >= B1200)
2171179Sbill 				lmode |= LCRTERA|LCRTKIL;
2181179Sbill 			continue;
2191179Sbill 		}
2201179Sbill 		if (eq("old")){
2211179Sbill 			ldisc = 0;
2221179Sbill 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2231179Sbill 				perror("ioctl");
2241179Sbill 			continue;
2251179Sbill 		}
2263797Sroot 		if (eq("dec")){
2273797Sroot 			mode.sg_erase = 0177;
2283797Sroot 			mode.sg_kill = CTRL(u);
2293797Sroot 			tc.t_intrc = CTRL(c);
2303797Sroot 			ldisc = NTTYDISC;
2313797Sroot 			lmode &= ~LPRTERA;
2323797Sroot 			lmode |= LCRTBS|LCTLECH|LDECCTQ;
2333797Sroot 			if (mode.sg_ospeed >= B1200)
2343797Sroot 				lmode |= LCRTERA|LCRTKIL;
2353797Sroot 			if (ioctl(1, TIOCSETD, &ldisc)<0)
2363797Sroot 				perror("ioctl");
2373797Sroot 			continue;
2383797Sroot 		}
2391179Sbill 		for (sp = special; sp->name; sp++)
2401179Sbill 			if (eq(sp->name)) {
2411179Sbill 				if (--argc == 0)
2421179Sbill 					goto done;
2431179Sbill 				if (**++argv == 'u')
2441179Sbill 					*sp->cp = 0377;
2451179Sbill 				else if (**argv == '^')
2463955Sroot 					*sp->cp = ((*argv)[1] == '?') ?
2471179Sbill 					    0177 : (*argv)[1] & 037;
2481179Sbill 				else
2491179Sbill 					*sp->cp = **argv;
2501179Sbill 				goto cont;
2511179Sbill 			}
2521179Sbill 		if (eq("gspeed")) {
2531179Sbill 			mode.sg_ispeed = B300;
2541179Sbill 			mode.sg_ospeed = B9600;
2551179Sbill 			continue;
2561179Sbill 		}
2571179Sbill 		if (eq("hup")) {
2581179Sbill 			ioctl(1, TIOCHPCL, NULL);
2591179Sbill 			continue;
2601179Sbill 		}
2611179Sbill 		for(i=0; speeds[i].string; i++)
2621179Sbill 			if(eq(speeds[i].string)) {
2631179Sbill 				mode.sg_ispeed = mode.sg_ospeed = speeds[i].speed;
2641179Sbill 				goto cont;
2651179Sbill 			}
2661179Sbill 		if (eq("speed")) {
2671179Sbill 			gtty(open("/dev/tty", 0), &mode);
2681179Sbill 			for(i=0; speeds[i].string; i++)
2691179Sbill 				if (mode.sg_ospeed == speeds[i].speed) {
2701179Sbill 					printf("%s\n", speeds[i].string);
2711179Sbill 					exit(0);
2721179Sbill 				}
2731179Sbill 			printf("unknown\n");
2741179Sbill 			exit(1);
2751179Sbill 		}
2761179Sbill 		for(i=0; modes[i].string; i++)
2771179Sbill 			if(eq(modes[i].string)) {
2781179Sbill 				mode.sg_flags &= ~modes[i].reset;
2791179Sbill 				mode.sg_flags |= modes[i].set;
2801179Sbill 				lmode &= ~modes[i].lreset;
2811179Sbill 				lmode |= modes[i].lset;
2821179Sbill 			}
2831179Sbill 		if(arg)
2841179Sbill 			fprintf(stderr,"unknown mode: %s\n", arg);
2851179Sbill cont:
2861179Sbill 		;
2871179Sbill 	}
2881179Sbill done:
2891179Sbill 	ioctl(1, TIOCSETN, &mode);
2901179Sbill 	ioctl(1, TIOCSETC, &tc);
2911179Sbill 	ioctl(1, TIOCSLTC, &ltc);
2921179Sbill 	ioctl(1, TIOCLSET, &lmode);
2931179Sbill }
2941179Sbill 
2951179Sbill eq(string)
2961179Sbill char *string;
2971179Sbill {
2981179Sbill 	int i;
2991179Sbill 
3001179Sbill 	if(!arg)
3011179Sbill 		return(0);
3021179Sbill 	i = 0;
3031179Sbill loop:
3041179Sbill 	if(arg[i] != string[i])
3051179Sbill 		return(0);
3061179Sbill 	if(arg[i++] != '\0')
3071179Sbill 		goto loop;
3081179Sbill 	arg = 0;
3091179Sbill 	return(1);
3101179Sbill }
3111179Sbill 
3121179Sbill prmodes(all)
3131179Sbill {
3141179Sbill 	register m;
3151179Sbill 	int any;
3161179Sbill 
3171179Sbill 	if(ldisc==NETLDISC)
3181179Sbill 		fprintf(stderr, "net discipline, ");
3191179Sbill 	else if(ldisc==NTTYDISC)
3201179Sbill 		fprintf(stderr, "new tty, ");
3211179Sbill 	else if(all==2)
3221179Sbill 		fprintf(stderr, "old tty, ");
3231179Sbill 	if(mode.sg_ispeed != mode.sg_ospeed) {
3241179Sbill 		prspeed("input speed ", mode.sg_ispeed);
3251179Sbill 		prspeed("output speed ", mode.sg_ospeed);
3261179Sbill 	} else
3271179Sbill 		prspeed("speed ", mode.sg_ispeed);
3281179Sbill 	fprintf(stderr, all==2 ? "\n" : "; ");
3291179Sbill 	m = mode.sg_flags;
3301179Sbill 	if(all==2 || (m&(EVENP|ODDP))!=(EVENP|ODDP)) {
3311179Sbill 		if(m & EVENP)	fprintf(stderr,"even ");
3321179Sbill 		if(m & ODDP)	fprintf(stderr,"odd ");
3331179Sbill 	}
3341179Sbill 	if(all==2 || m&RAW)
3351179Sbill 		fprintf(stderr,"-raw "+((m&RAW)!=0));
3361179Sbill 	if(all==2 || (m&CRMOD)==0)
3371179Sbill 		fprintf(stderr,"-nl "+((m&CRMOD)==0));
3381179Sbill 	if(all==2 || (m&ECHO)==0)
3391179Sbill 		fprintf(stderr,"-echo "+((m&ECHO)!=0));
3401179Sbill 	if(all==2 || (m&LCASE))
3411179Sbill 		fprintf(stderr,"-lcase "+((m&LCASE)!=0));
3421179Sbill 	if(all==2 || (m&TANDEM))
3431179Sbill 		fprintf(stderr,"-tandem "+((m&TANDEM)!=0));
3441179Sbill 	fprintf(stderr,"-tabs "+((m&XTABS)!=XTABS));
3451179Sbill 	if(all==2 || (m&CBREAK))
3461179Sbill 		fprintf(stderr,"-cbreak "+((m&CBREAK)!=0));
3471179Sbill 	if(all==2 || (m&NLDELAY))
3481179Sbill 		delay((m&NLDELAY)/NL1,	"nl");
3491179Sbill 	if ((m&TBDELAY)!=XTABS)
3501179Sbill 		delay((m&TBDELAY)/TAB1,	"tab");
3511179Sbill 	if(all==2 || (m&CRDELAY))
3521179Sbill 		delay((m&CRDELAY)/CR1,	"cr");
3531179Sbill 	if(all==2 || (m&VTDELAY))
3541179Sbill 		delay((m&VTDELAY)/FF1,	"ff");
3551179Sbill 	if(all==2 || (m&BSDELAY))
3561179Sbill 		delay((m&BSDELAY)/BS1,	"bs");
3571179Sbill 	if (all)
3581179Sbill 		fprintf(stderr,"\n");
3591179Sbill #define	lpit(what,str) \
3601179Sbill 	if (all==2||(lmode&what)) { \
3611179Sbill 		fprintf(stderr,str+((lmode&what)!=0)); any++; \
3621179Sbill 	}
3631179Sbill 	if (ldisc == NTTYDISC) {
3641179Sbill 		int newcrt = (lmode&(LCTLECH|LCRTBS)) == (LCTLECH|LCRTBS) &&
3651179Sbill 		    (lmode&(LCRTERA|LCRTKIL)) ==
3661179Sbill 		      ((mode.sg_ospeed > B300) ? LCRTERA|LCRTKIL : 0);
3671179Sbill 		if (newcrt) {
3681179Sbill 			if (all==2)
3691402Sbill 				fprintf(stderr, "crt: (crtbs crterase crtkill ctlecho) ");
3701179Sbill 			else
3711402Sbill 				fprintf(stderr, "crt ");
3721179Sbill 			any++;
3731179Sbill 		} else {
3741179Sbill 			lpit(LCRTBS, "-crtbs ");
3751179Sbill 			lpit(LCRTERA, "-crterase ");
3761179Sbill 			lpit(LCRTKIL, "-crtkill ");
3771179Sbill 			lpit(LCTLECH, "-ctlecho ");
3781179Sbill 			lpit(LPRTERA, "-prterase ");
3791179Sbill 		}
3801179Sbill 		lpit(LTOSTOP, "-tostop ");
3811179Sbill 		lpit(LINTRUP, "-intrup ");
3821179Sbill 		if (all==2) {
3831179Sbill 			fprintf(stderr, "\n");
3841179Sbill 			any = 0;
3851179Sbill 		}
3861179Sbill 		lpit(LTILDE, "-tilde ");
3871179Sbill 		lpit(LFLUSHO, "-flusho ");
3881179Sbill 		lpit(LMDMBUF, "-mdmbuf ");
3891179Sbill 		lpit(LLITOUT, "-litout ");
3901179Sbill 		lpit(LNOHANG, "-nohang ");
391*4017Sroot 		if (any) {
392*4017Sroot 			fprintf(stderr,"\n");
393*4017Sroot 			any = 0;
394*4017Sroot 		}
3951179Sbill 		lpit(LETXACK, "-etxack ");
3961179Sbill 		lpit(LPENDIN, "-pendin ");
397*4017Sroot 		lpit(LDECCTQ, "-decctlq ");
398*4017Sroot 		lpit(LNOFLSH, "-noflsh ");
3991179Sbill 		if (any)
4001179Sbill 			fprintf(stderr,"\n");
4011179Sbill 	} else if (!all)
4021179Sbill 		fprintf(stderr,"\n");
4031179Sbill 	if (all) {
4041179Sbill 		switch (ldisc) {
4051179Sbill 
4061179Sbill 		case 0:
4071179Sbill 			fprintf(stderr,"\
4081179Sbill erase  kill   intr   quit   stop   eof\
4091179Sbill \n");
4101179Sbill 			pcol(mode.sg_erase, -1);
4111179Sbill 			pcol(mode.sg_kill, -1);
4121179Sbill 			pcol(tc.t_intrc, -1);
4131179Sbill 			pcol(tc.t_quitc, -1);
4141179Sbill 			pcol(tc.t_stopc, tc.t_startc);
4151179Sbill 			pcol(tc.t_eofc, tc.t_brkc);
4161179Sbill 			fprintf(stderr,"\n");
4171179Sbill 			break;
4181179Sbill 
4191179Sbill 		case NTTYDISC:
4201179Sbill 			fprintf(stderr,"\
4211179Sbill erase  kill   werase rprnt  flush  lnext  susp   intr   quit   stop   eof\
4221179Sbill \n");
4231179Sbill 			pcol(mode.sg_erase, -1);
4241179Sbill 			pcol(mode.sg_kill, -1);
4251179Sbill 			pcol(ltc.t_werasc, -1);
4261179Sbill 			pcol(ltc.t_rprntc, -1);
4271179Sbill 			pcol(ltc.t_flushc, -1);
4281179Sbill 			pcol(ltc.t_lnextc, -1);
4291179Sbill 			pcol(ltc.t_suspc, ltc.t_dsuspc);
4301179Sbill 			pcol(tc.t_intrc, -1);
4311179Sbill 			pcol(tc.t_quitc, -1);
4321179Sbill 			pcol(tc.t_stopc, tc.t_startc);
4331179Sbill 			pcol(tc.t_eofc, tc.t_brkc);
4341179Sbill 			fprintf(stderr,"\n");
4351179Sbill 			break;
4361179Sbill 		}
4371179Sbill 	} else if (ldisc != NETLDISC) {
4381179Sbill 		register struct special *sp;
4391179Sbill 		int first = 1;
4401179Sbill 		for (sp = special; sp->name; sp++) {
4411179Sbill 			if ((*sp->cp&0377) != (sp->def&0377)) {
4421179Sbill 				pit(*sp->cp, sp->name, first ? "" : ", ");
4431179Sbill 				first = 0;
4441179Sbill 			};
4451179Sbill 			if (sp->cp == &tc.t_brkc && ldisc == 0)
4461179Sbill 				break;
4471179Sbill 		}
4481179Sbill 		if (first == 0)
4491179Sbill 			fprintf(stderr, "\n");
4501179Sbill 	}
4511179Sbill }
4521179Sbill 
4531179Sbill pcol(ch1, ch2)
4541179Sbill 	int ch1, ch2;
4551179Sbill {
4561179Sbill 	int nout = 0;
4571179Sbill 
4581179Sbill 	ch1 &= 0377;
4591179Sbill 	ch2 &= 0377;
4601179Sbill 	if (ch1 == ch2)
4611179Sbill 		ch2 = 0377;
4621179Sbill 	for (; ch1 != 0377 || ch2 != 0377; ch1 = ch2, ch2 = 0377) {
4631179Sbill 		if (ch1 == 0377)
4641179Sbill 			continue;
4651179Sbill 		if (ch1 & 0200) {
4661179Sbill 			fprintf(stderr, "M-");
4671179Sbill 			nout += 2;
4681179Sbill 			ch1 &= ~ 0200;
4691179Sbill 		}
4701179Sbill 		if (ch1 == 0177) {
4711179Sbill 			fprintf(stderr, "^");
4721179Sbill 			nout++;
4731179Sbill 			ch1 = '?';
4741179Sbill 		} else if (ch1 < ' ') {
4751179Sbill 			fprintf(stderr, "^");
4761179Sbill 			nout++;
4771179Sbill 			ch1 += '@';
4781179Sbill 		}
4791179Sbill 		fprintf(stderr, "%c", ch1);
4801179Sbill 		nout++;
4811179Sbill 		if (ch2 != 0377) {
4821179Sbill 			fprintf(stderr, "/");
4831179Sbill 			nout++;
4841179Sbill 		}
4851179Sbill 	}
4861179Sbill 	while (nout < 7) {
4871179Sbill 		fprintf(stderr, " ");
4881179Sbill 		nout++;
4891179Sbill 	}
4901179Sbill }
4911179Sbill 
4921179Sbill pit(what, itsname, sep)
4931179Sbill 	unsigned what;
4941179Sbill 	char *itsname, *sep;
4951179Sbill {
4961179Sbill 
4971179Sbill 	what &= 0377;
4981179Sbill 	fprintf(stderr, "%s%s", sep, itsname);
4991179Sbill 	if (what == 0377) {
5001179Sbill 		fprintf(stderr, " <undef>");
5011179Sbill 		return;
5021179Sbill 	}
5031179Sbill 	fprintf(stderr, " = ");
5041179Sbill 	if (what & 0200) {
5051179Sbill 		fprintf(stderr, "M-");
5061179Sbill 		what &= ~ 0200;
5071179Sbill 	}
5081179Sbill 	if (what == 0177) {
5091179Sbill 		fprintf(stderr, "^");
5101179Sbill 		what = '?';
5111179Sbill 	} else if (what < ' ') {
5121179Sbill 		fprintf(stderr, "^");
5131179Sbill 		what += '@';
5141179Sbill 	}
5151179Sbill 	fprintf(stderr, "%c", what);
5161179Sbill }
5171179Sbill 
5181179Sbill delay(m, s)
5191179Sbill char *s;
5201179Sbill {
5211179Sbill 
5221179Sbill 	if(m)
5231179Sbill 		fprintf(stderr,"%s%d ", s, m);
5241179Sbill }
5251179Sbill 
5261179Sbill int	speed[] = {
5271179Sbill 	0,50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600,0,0
5281179Sbill };
5291179Sbill 
5301179Sbill prspeed(c, s)
5311179Sbill char *c;
5321179Sbill {
5331179Sbill 
5341179Sbill 	fprintf(stderr,"%s%d baud",  c, speed[s]);
5351179Sbill }
536