xref: /illumos-gate/usr/src/cmd/bnu/setmode.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
2*462be471Sceastha  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
3*462be471Sceastha  * Use is subject to license terms.
47c478bd9Sstevel@tonic-gate  */
57c478bd9Sstevel@tonic-gate 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * Copyright (c) 1983 Regents of the University of California.
87c478bd9Sstevel@tonic-gate  * All rights reserved. The Berkeley software License Agreement
97c478bd9Sstevel@tonic-gate  * specifies the terms and conditions for redistribution.
107c478bd9Sstevel@tonic-gate  */
117c478bd9Sstevel@tonic-gate 
127c478bd9Sstevel@tonic-gate /*
137c478bd9Sstevel@tonic-gate  * Stolen from ucb/lpr/printjob.c
147c478bd9Sstevel@tonic-gate  */
157c478bd9Sstevel@tonic-gate 
167c478bd9Sstevel@tonic-gate #include <string.h>
177c478bd9Sstevel@tonic-gate #include "uucp.h"
187c478bd9Sstevel@tonic-gate 
197c478bd9Sstevel@tonic-gate static struct termios termios_set;
207c478bd9Sstevel@tonic-gate static struct termios termios_clear;
217c478bd9Sstevel@tonic-gate 
22*462be471Sceastha static int parse_modes(char *modes);
23*462be471Sceastha static void setty(int);
24*462be471Sceastha 
25*462be471Sceastha int
setmode(modes,fd)267c478bd9Sstevel@tonic-gate setmode(modes, fd)
277c478bd9Sstevel@tonic-gate 	char *modes;
287c478bd9Sstevel@tonic-gate 	int fd;
297c478bd9Sstevel@tonic-gate {
307c478bd9Sstevel@tonic-gate 	if (parse_modes(modes))
317c478bd9Sstevel@tonic-gate 		setty(fd);
32*462be471Sceastha 	return (0);
337c478bd9Sstevel@tonic-gate }
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate struct mds {
367c478bd9Sstevel@tonic-gate 	char	*string;
377c478bd9Sstevel@tonic-gate 	unsigned long	set;
387c478bd9Sstevel@tonic-gate 	unsigned long	reset;
397c478bd9Sstevel@tonic-gate };
407c478bd9Sstevel@tonic-gate 						/* Control Modes */
417c478bd9Sstevel@tonic-gate static struct mds cmodes[] = {
427c478bd9Sstevel@tonic-gate 	"-parity", CS8, PARENB|CSIZE,
437c478bd9Sstevel@tonic-gate 	"-evenp", CS8, PARENB|CSIZE,
447c478bd9Sstevel@tonic-gate 	"-oddp", CS8, PARENB|PARODD|CSIZE,
457c478bd9Sstevel@tonic-gate 	"parity", PARENB|CS7, PARODD|CSIZE,
467c478bd9Sstevel@tonic-gate 	"evenp", PARENB|CS7, PARODD|CSIZE,
477c478bd9Sstevel@tonic-gate 	"oddp", PARENB|PARODD|CS7, CSIZE,
487c478bd9Sstevel@tonic-gate 	"parenb", PARENB, 0,
497c478bd9Sstevel@tonic-gate 	"-parenb", 0, PARENB,
507c478bd9Sstevel@tonic-gate 	"parodd", PARODD, 0,
517c478bd9Sstevel@tonic-gate 	"-parodd", 0, PARODD,
527c478bd9Sstevel@tonic-gate 	"cs8", CS8, CSIZE,
537c478bd9Sstevel@tonic-gate 	"cs7", CS7, CSIZE,
547c478bd9Sstevel@tonic-gate 	"cs6", CS6, CSIZE,
557c478bd9Sstevel@tonic-gate 	"cs5", CS5, CSIZE,
567c478bd9Sstevel@tonic-gate 	"cstopb", CSTOPB, 0,
577c478bd9Sstevel@tonic-gate 	"-cstopb", 0, CSTOPB,
587c478bd9Sstevel@tonic-gate 	"stopb", CSTOPB, 0,
597c478bd9Sstevel@tonic-gate 	"-stopb", 0, CSTOPB,
607c478bd9Sstevel@tonic-gate 	"hupcl", HUPCL, 0,
617c478bd9Sstevel@tonic-gate 	"hup", HUPCL, 0,
627c478bd9Sstevel@tonic-gate 	"-hupcl", 0, HUPCL,
637c478bd9Sstevel@tonic-gate 	"-hup", 0, HUPCL,
647c478bd9Sstevel@tonic-gate 	"clocal", CLOCAL, 0,
657c478bd9Sstevel@tonic-gate 	"-clocal", 0, CLOCAL,
667c478bd9Sstevel@tonic-gate 	"nohang", CLOCAL, 0,
677c478bd9Sstevel@tonic-gate 	"-nohang", 0, CLOCAL,
687c478bd9Sstevel@tonic-gate #if 0		/* this bit isn't supported */
697c478bd9Sstevel@tonic-gate 	"loblk", LOBLK, 0,
707c478bd9Sstevel@tonic-gate 	"-loblk", 0, LOBLK,
717c478bd9Sstevel@tonic-gate #endif
727c478bd9Sstevel@tonic-gate 	"cread", CREAD, 0,
737c478bd9Sstevel@tonic-gate 	"-cread", 0, CREAD,
747c478bd9Sstevel@tonic-gate #ifndef CRTSCTS
757c478bd9Sstevel@tonic-gate #define	CRTSCTS	0x80000000
767c478bd9Sstevel@tonic-gate #endif
777c478bd9Sstevel@tonic-gate 	"crtscts", CRTSCTS, 0,
787c478bd9Sstevel@tonic-gate 	"-crtscts", 0, CRTSCTS,
797c478bd9Sstevel@tonic-gate #ifndef CRTSXOFF
807c478bd9Sstevel@tonic-gate #define	CRTSXOFF 0x40000000
817c478bd9Sstevel@tonic-gate #endif
827c478bd9Sstevel@tonic-gate 	"crtsxoff", CRTSXOFF, 0,
837c478bd9Sstevel@tonic-gate 	"-crtsxoff", 0, CRTSXOFF,
847c478bd9Sstevel@tonic-gate 	"litout", CS8, (CSIZE|PARENB),
857c478bd9Sstevel@tonic-gate 	"-litout", (CS7|PARENB), CSIZE,
867c478bd9Sstevel@tonic-gate 	"pass8", CS8, (CSIZE|PARENB),
877c478bd9Sstevel@tonic-gate 	"-pass8", (CS7|PARENB), CSIZE,
887c478bd9Sstevel@tonic-gate 	"raw", CS8, (CSIZE|PARENB),
897c478bd9Sstevel@tonic-gate 	"-raw", (CS7|PARENB), CSIZE,
907c478bd9Sstevel@tonic-gate 	"cooked", (CS7|PARENB), CSIZE,
917c478bd9Sstevel@tonic-gate 	"sane", (CS7|PARENB|CREAD), (CSIZE|PARODD|CLOCAL),
927c478bd9Sstevel@tonic-gate 	0
937c478bd9Sstevel@tonic-gate };
947c478bd9Sstevel@tonic-gate 						/* Input Modes */
957c478bd9Sstevel@tonic-gate static struct mds imodes[] = {
967c478bd9Sstevel@tonic-gate 	"ignbrk", IGNBRK, 0,
977c478bd9Sstevel@tonic-gate 	"-ignbrk", 0, IGNBRK,
987c478bd9Sstevel@tonic-gate 	"brkint", BRKINT, 0,
997c478bd9Sstevel@tonic-gate 	"-brkint", 0, BRKINT,
1007c478bd9Sstevel@tonic-gate 	"ignpar", IGNPAR, 0,
1017c478bd9Sstevel@tonic-gate 	"-ignpar", 0, IGNPAR,
1027c478bd9Sstevel@tonic-gate 	"parmrk", PARMRK, 0,
1037c478bd9Sstevel@tonic-gate 	"-parmrk", 0, PARMRK,
1047c478bd9Sstevel@tonic-gate 	"inpck", INPCK, 0,
1057c478bd9Sstevel@tonic-gate 	"-inpck", 0, INPCK,
1067c478bd9Sstevel@tonic-gate 	"istrip", ISTRIP, 0,
1077c478bd9Sstevel@tonic-gate 	"-istrip", 0, ISTRIP,
1087c478bd9Sstevel@tonic-gate 	"inlcr", INLCR, 0,
1097c478bd9Sstevel@tonic-gate 	"-inlcr", 0, INLCR,
1107c478bd9Sstevel@tonic-gate 	"igncr", IGNCR, 0,
1117c478bd9Sstevel@tonic-gate 	"-igncr", 0, IGNCR,
1127c478bd9Sstevel@tonic-gate 	"icrnl", ICRNL, 0,
1137c478bd9Sstevel@tonic-gate 	"-icrnl", 0, ICRNL,
1147c478bd9Sstevel@tonic-gate 	"-nl", ICRNL, (INLCR|IGNCR),
1157c478bd9Sstevel@tonic-gate 	"nl", 0, ICRNL,
1167c478bd9Sstevel@tonic-gate 	"iuclc", IUCLC, 0,
1177c478bd9Sstevel@tonic-gate 	"-iuclc", 0, IUCLC,
1187c478bd9Sstevel@tonic-gate 	"lcase", IUCLC, 0,
1197c478bd9Sstevel@tonic-gate 	"-lcase", 0, IUCLC,
1207c478bd9Sstevel@tonic-gate 	"LCASE", IUCLC, 0,
1217c478bd9Sstevel@tonic-gate 	"-LCASE", 0, IUCLC,
1227c478bd9Sstevel@tonic-gate 	"ixon", IXON, 0,
1237c478bd9Sstevel@tonic-gate 	"-ixon", 0, IXON,
1247c478bd9Sstevel@tonic-gate 	"ixany", IXANY, 0,
1257c478bd9Sstevel@tonic-gate 	"-ixany", 0, IXANY,
1267c478bd9Sstevel@tonic-gate 	"decctlq", 0, IXANY,
1277c478bd9Sstevel@tonic-gate 	"-decctlq", IXANY, 0,
1287c478bd9Sstevel@tonic-gate 	"ixoff", IXOFF, 0,
1297c478bd9Sstevel@tonic-gate 	"-ixoff", 0, IXOFF,
1307c478bd9Sstevel@tonic-gate 	"tandem", IXOFF, 0,
1317c478bd9Sstevel@tonic-gate 	"-tandem", 0, IXOFF,
1327c478bd9Sstevel@tonic-gate 	"imaxbel", IMAXBEL, 0,
1337c478bd9Sstevel@tonic-gate 	"-imaxbel", 0, IMAXBEL,
1347c478bd9Sstevel@tonic-gate 	"pass8", 0, ISTRIP,
1357c478bd9Sstevel@tonic-gate 	"-pass8", ISTRIP, 0,
1367c478bd9Sstevel@tonic-gate 	"raw", 0, (unsigned long)-1,
1377c478bd9Sstevel@tonic-gate 	"-raw", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL), 0,
1387c478bd9Sstevel@tonic-gate 	"cooked", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON), 0,
1397c478bd9Sstevel@tonic-gate 	"sane", (BRKINT|IGNPAR|ISTRIP|ICRNL|IXON|IMAXBEL),
1407c478bd9Sstevel@tonic-gate 		(IGNBRK|PARMRK|INPCK|INLCR|IGNCR|IUCLC|IXOFF),
1417c478bd9Sstevel@tonic-gate 	0
1427c478bd9Sstevel@tonic-gate };
1437c478bd9Sstevel@tonic-gate 						/* Local Modes */
1447c478bd9Sstevel@tonic-gate static struct mds lmodes[] = {
1457c478bd9Sstevel@tonic-gate 	"isig", ISIG, 0,
1467c478bd9Sstevel@tonic-gate 	"-isig", 0, ISIG,
1477c478bd9Sstevel@tonic-gate 	"noisig", 0, ISIG,
1487c478bd9Sstevel@tonic-gate 	"-noisig", ISIG, 0,
1497c478bd9Sstevel@tonic-gate 	"iexten", IEXTEN, 0,
1507c478bd9Sstevel@tonic-gate 	"-iexten", 0, IEXTEN,
1517c478bd9Sstevel@tonic-gate 	"icanon", ICANON, 0,
1527c478bd9Sstevel@tonic-gate 	"-icanon", 0, ICANON,
1537c478bd9Sstevel@tonic-gate 	"cbreak", 0, ICANON,
1547c478bd9Sstevel@tonic-gate 	"-cbreak", ICANON, 0,
1557c478bd9Sstevel@tonic-gate 	"xcase", XCASE, 0,
1567c478bd9Sstevel@tonic-gate 	"-xcase", 0, XCASE,
1577c478bd9Sstevel@tonic-gate 	"lcase", XCASE, 0,
1587c478bd9Sstevel@tonic-gate 	"-lcase", 0, XCASE,
1597c478bd9Sstevel@tonic-gate 	"LCASE", XCASE, 0,
1607c478bd9Sstevel@tonic-gate 	"-LCASE", 0, XCASE,
1617c478bd9Sstevel@tonic-gate 	"echo", ECHO, 0,
1627c478bd9Sstevel@tonic-gate 	"-echo", 0, ECHO,
1637c478bd9Sstevel@tonic-gate 	"echoe", ECHOE, 0,
1647c478bd9Sstevel@tonic-gate 	"-echoe", 0, ECHOE,
1657c478bd9Sstevel@tonic-gate 	"crterase", ECHOE, 0,
1667c478bd9Sstevel@tonic-gate 	"-crterase", 0, ECHOE,
1677c478bd9Sstevel@tonic-gate 	"echok", ECHOK, 0,
1687c478bd9Sstevel@tonic-gate 	"-echok", 0, ECHOK,
1697c478bd9Sstevel@tonic-gate 	"lfkc", ECHOK, 0,
1707c478bd9Sstevel@tonic-gate 	"-lfkc", 0, ECHOK,
1717c478bd9Sstevel@tonic-gate 	"echonl", ECHONL, 0,
1727c478bd9Sstevel@tonic-gate 	"-echonl", 0, ECHONL,
1737c478bd9Sstevel@tonic-gate 	"noflsh", NOFLSH, 0,
1747c478bd9Sstevel@tonic-gate 	"-noflsh", 0, NOFLSH,
1757c478bd9Sstevel@tonic-gate 	"tostop", TOSTOP, 0,
1767c478bd9Sstevel@tonic-gate 	"-tostop", 0, TOSTOP,
1777c478bd9Sstevel@tonic-gate 	"echoctl", ECHOCTL, 0,
1787c478bd9Sstevel@tonic-gate 	"-echoctl", 0, ECHOCTL,
1797c478bd9Sstevel@tonic-gate 	"ctlecho", ECHOCTL, 0,
1807c478bd9Sstevel@tonic-gate 	"-ctlecho", 0, ECHOCTL,
1817c478bd9Sstevel@tonic-gate 	"echoprt", ECHOPRT, 0,
1827c478bd9Sstevel@tonic-gate 	"-echoprt", 0, ECHOPRT,
1837c478bd9Sstevel@tonic-gate 	"prterase", ECHOPRT, 0,
1847c478bd9Sstevel@tonic-gate 	"-prterase", 0, ECHOPRT,
1857c478bd9Sstevel@tonic-gate 	"echoke", ECHOKE, 0,
1867c478bd9Sstevel@tonic-gate 	"-echoke", 0, ECHOKE,
1877c478bd9Sstevel@tonic-gate 	"crtkill", ECHOKE, 0,
1887c478bd9Sstevel@tonic-gate 	"-crtkill", 0, ECHOKE,
1897c478bd9Sstevel@tonic-gate #if 0		/* this bit isn't supported yet */
1907c478bd9Sstevel@tonic-gate 	"defecho", DEFECHO, 0,
1917c478bd9Sstevel@tonic-gate 	"-defecho", 0, DEFECHO,
1927c478bd9Sstevel@tonic-gate #endif
1937c478bd9Sstevel@tonic-gate 	"raw", 0, (ISIG|ICANON|XCASE|IEXTEN),
1947c478bd9Sstevel@tonic-gate 	"-raw", (ISIG|ICANON|IEXTEN), 0,
1957c478bd9Sstevel@tonic-gate 	"cooked", (ISIG|ICANON), 0,
1967c478bd9Sstevel@tonic-gate 	"sane", (ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE),
1977c478bd9Sstevel@tonic-gate 		(XCASE|ECHOPRT|ECHONL|NOFLSH),
1987c478bd9Sstevel@tonic-gate 	0,
1997c478bd9Sstevel@tonic-gate };
2007c478bd9Sstevel@tonic-gate 						/* Output Modes */
2017c478bd9Sstevel@tonic-gate static struct mds omodes[] = {
2027c478bd9Sstevel@tonic-gate 	"opost", OPOST, 0,
2037c478bd9Sstevel@tonic-gate 	"-opost", 0, OPOST,
2047c478bd9Sstevel@tonic-gate 	"nopost", 0, OPOST,
2057c478bd9Sstevel@tonic-gate 	"-nopost", OPOST, 0,
2067c478bd9Sstevel@tonic-gate 	"olcuc", OLCUC, 0,
2077c478bd9Sstevel@tonic-gate 	"-olcuc", 0, OLCUC,
2087c478bd9Sstevel@tonic-gate 	"lcase", OLCUC, 0,
2097c478bd9Sstevel@tonic-gate 	"-lcase", 0, OLCUC,
2107c478bd9Sstevel@tonic-gate 	"LCASE", OLCUC, 0,
2117c478bd9Sstevel@tonic-gate 	"-LCASE", 0, OLCUC,
2127c478bd9Sstevel@tonic-gate 	"onlcr", ONLCR, 0,
2137c478bd9Sstevel@tonic-gate 	"-onlcr", 0, ONLCR,
2147c478bd9Sstevel@tonic-gate 	"-nl", ONLCR, (OCRNL|ONLRET),
2157c478bd9Sstevel@tonic-gate 	"nl", 0, ONLCR,
2167c478bd9Sstevel@tonic-gate 	"ocrnl", OCRNL, 0,
2177c478bd9Sstevel@tonic-gate 	"-ocrnl", 0, OCRNL,
2187c478bd9Sstevel@tonic-gate 	"onocr", ONOCR, 0,
2197c478bd9Sstevel@tonic-gate 	"-onocr", 0, ONOCR,
2207c478bd9Sstevel@tonic-gate 	"onlret", ONLRET, 0,
2217c478bd9Sstevel@tonic-gate 	"-onlret", 0, ONLRET,
2227c478bd9Sstevel@tonic-gate 	"fill", OFILL, OFDEL,
2237c478bd9Sstevel@tonic-gate 	"-fill", 0, OFILL|OFDEL,
2247c478bd9Sstevel@tonic-gate 	"nul-fill", OFILL, OFDEL,
2257c478bd9Sstevel@tonic-gate 	"del-fill", OFILL|OFDEL, 0,
2267c478bd9Sstevel@tonic-gate 	"ofill", OFILL, 0,
2277c478bd9Sstevel@tonic-gate 	"-ofill", 0, OFILL,
2287c478bd9Sstevel@tonic-gate 	"ofdel", OFDEL, 0,
2297c478bd9Sstevel@tonic-gate 	"-ofdel", 0, OFDEL,
2307c478bd9Sstevel@tonic-gate 	"cr0", CR0, CRDLY,
2317c478bd9Sstevel@tonic-gate 	"cr1", CR1, CRDLY,
2327c478bd9Sstevel@tonic-gate 	"cr2", CR2, CRDLY,
2337c478bd9Sstevel@tonic-gate 	"cr3", CR3, CRDLY,
2347c478bd9Sstevel@tonic-gate 	"tab0", TAB0, TABDLY,
2357c478bd9Sstevel@tonic-gate 	"tabs", TAB0, TABDLY,
2367c478bd9Sstevel@tonic-gate 	"tab1", TAB1, TABDLY,
2377c478bd9Sstevel@tonic-gate 	"tab2", TAB2, TABDLY,
2387c478bd9Sstevel@tonic-gate 	"-tabs", XTABS, TABDLY,
2397c478bd9Sstevel@tonic-gate 	"tab3", XTABS, TABDLY,
2407c478bd9Sstevel@tonic-gate 	"nl0", NL0, NLDLY,
2417c478bd9Sstevel@tonic-gate 	"nl1", NL1, NLDLY,
2427c478bd9Sstevel@tonic-gate 	"ff0", FF0, FFDLY,
2437c478bd9Sstevel@tonic-gate 	"ff1", FF1, FFDLY,
2447c478bd9Sstevel@tonic-gate 	"vt0", VT0, VTDLY,
2457c478bd9Sstevel@tonic-gate 	"vt1", VT1, VTDLY,
2467c478bd9Sstevel@tonic-gate 	"bs0", BS0, BSDLY,
2477c478bd9Sstevel@tonic-gate 	"bs1", BS1, BSDLY,
2487c478bd9Sstevel@tonic-gate #if 0		/* these bits aren't supported yet */
2497c478bd9Sstevel@tonic-gate 	"pageout", PAGEOUT, 0,
2507c478bd9Sstevel@tonic-gate 	"-pageout", 0, PAGEOUT,
2517c478bd9Sstevel@tonic-gate 	"wrap", WRAP, 0,
2527c478bd9Sstevel@tonic-gate 	"-wrap", 0, WRAP,
2537c478bd9Sstevel@tonic-gate #endif
2547c478bd9Sstevel@tonic-gate 	"litout", 0, OPOST,
2557c478bd9Sstevel@tonic-gate 	"-litout", OPOST, 0,
2567c478bd9Sstevel@tonic-gate 	"raw", 0, OPOST,
2577c478bd9Sstevel@tonic-gate 	"-raw", OPOST, 0,
2587c478bd9Sstevel@tonic-gate 	"cooked", OPOST, 0,
2597c478bd9Sstevel@tonic-gate 	"33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2607c478bd9Sstevel@tonic-gate 	"tty33", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2617c478bd9Sstevel@tonic-gate 	"tn", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2627c478bd9Sstevel@tonic-gate 	"tn300", CR1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2637c478bd9Sstevel@tonic-gate 	"ti", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2647c478bd9Sstevel@tonic-gate 	"ti700", CR2, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2657c478bd9Sstevel@tonic-gate 	"05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2667c478bd9Sstevel@tonic-gate 	"vt05", NL1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2677c478bd9Sstevel@tonic-gate 	"tek", FF1, (CRDLY|TABDLY|NLDLY|FFDLY|VTDLY|BSDLY),
2687c478bd9Sstevel@tonic-gate 	"37", (FF1|VT1|CR2|TAB1|NL1), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
2697c478bd9Sstevel@tonic-gate 	"tty37", (FF1|VT1|CR2|TAB1|NL1), (NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
2707c478bd9Sstevel@tonic-gate 	"sane", (OPOST|ONLCR), (OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL|
2717c478bd9Sstevel@tonic-gate 			NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY),
2727c478bd9Sstevel@tonic-gate 	0,
2737c478bd9Sstevel@tonic-gate };
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate /*
2767c478bd9Sstevel@tonic-gate  * Parse a set of modes.
2777c478bd9Sstevel@tonic-gate  */
2787c478bd9Sstevel@tonic-gate static int
parse_modes(modes)2797c478bd9Sstevel@tonic-gate parse_modes(modes)
2807c478bd9Sstevel@tonic-gate 	char *modes;
2817c478bd9Sstevel@tonic-gate {
282*462be471Sceastha 	char *curtoken;
283*462be471Sceastha 	int match;
284*462be471Sceastha 	int i;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 	termios_clear.c_iflag = 0;
2877c478bd9Sstevel@tonic-gate 	termios_clear.c_oflag = 0;
2887c478bd9Sstevel@tonic-gate 	termios_clear.c_cflag = 0;
2897c478bd9Sstevel@tonic-gate 	termios_clear.c_lflag = 0;
2907c478bd9Sstevel@tonic-gate 	termios_set.c_iflag = 0;
2917c478bd9Sstevel@tonic-gate 	termios_set.c_oflag = 0;
2927c478bd9Sstevel@tonic-gate 	termios_set.c_cflag = 0;
2937c478bd9Sstevel@tonic-gate 	termios_set.c_lflag = 0;
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 	curtoken = strtok(modes, ",");
2967c478bd9Sstevel@tonic-gate 	while (curtoken != NULL) {
2977c478bd9Sstevel@tonic-gate 		match = 0;
2987c478bd9Sstevel@tonic-gate 		for (i = 0; imodes[i].string != NULL; i++) {
2997c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, imodes[i].string) == 0) {
3007c478bd9Sstevel@tonic-gate 				match++;
3017c478bd9Sstevel@tonic-gate 				termios_clear.c_iflag |= imodes[i].reset;
3027c478bd9Sstevel@tonic-gate 				termios_set.c_iflag |= imodes[i].set;
3037c478bd9Sstevel@tonic-gate 			}
3047c478bd9Sstevel@tonic-gate 		}
3057c478bd9Sstevel@tonic-gate 		for (i = 0; omodes[i].string != NULL; i++) {
3067c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, omodes[i].string) == 0) {
3077c478bd9Sstevel@tonic-gate 				match++;
3087c478bd9Sstevel@tonic-gate 				termios_clear.c_oflag |= omodes[i].reset;
3097c478bd9Sstevel@tonic-gate 				termios_set.c_oflag |= omodes[i].set;
3107c478bd9Sstevel@tonic-gate 			}
3117c478bd9Sstevel@tonic-gate 		}
3127c478bd9Sstevel@tonic-gate 		for (i = 0; cmodes[i].string != NULL; i++) {
3137c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, cmodes[i].string) == 0) {
3147c478bd9Sstevel@tonic-gate 				match++;
3157c478bd9Sstevel@tonic-gate 				termios_clear.c_cflag |= cmodes[i].reset;
3167c478bd9Sstevel@tonic-gate 				termios_set.c_cflag |= cmodes[i].set;
3177c478bd9Sstevel@tonic-gate 			}
3187c478bd9Sstevel@tonic-gate 		}
3197c478bd9Sstevel@tonic-gate 		for (i = 0; lmodes[i].string != NULL; i++) {
3207c478bd9Sstevel@tonic-gate 			if (strcmp(curtoken, lmodes[i].string) == 0) {
3217c478bd9Sstevel@tonic-gate 				match++;
3227c478bd9Sstevel@tonic-gate 				termios_clear.c_lflag |= lmodes[i].reset;
3237c478bd9Sstevel@tonic-gate 				termios_set.c_lflag |= lmodes[i].set;
3247c478bd9Sstevel@tonic-gate 			}
3257c478bd9Sstevel@tonic-gate 		}
3267c478bd9Sstevel@tonic-gate 		if (!match) {
3277c478bd9Sstevel@tonic-gate 			CDEBUG(5, "unknown mode %s in STTY= string", curtoken);
3287c478bd9Sstevel@tonic-gate 			return (0);
3297c478bd9Sstevel@tonic-gate 		}
3307c478bd9Sstevel@tonic-gate 		curtoken = strtok((char *)NULL, ",");
3317c478bd9Sstevel@tonic-gate 	}
3327c478bd9Sstevel@tonic-gate 	return (1);
3337c478bd9Sstevel@tonic-gate }
3347c478bd9Sstevel@tonic-gate 
3357c478bd9Sstevel@tonic-gate /*
3367c478bd9Sstevel@tonic-gate  * setup tty lines.
3377c478bd9Sstevel@tonic-gate  */
338*462be471Sceastha static void
setty(int fd)339*462be471Sceastha setty(int fd)
3407c478bd9Sstevel@tonic-gate {
3417c478bd9Sstevel@tonic-gate 	struct termios termios;
3427c478bd9Sstevel@tonic-gate 
3437c478bd9Sstevel@tonic-gate 	if ((*Ioctl)(fd, TCGETS, &termios) < 0) {
3447c478bd9Sstevel@tonic-gate 		CDEBUG(5, "ioctl(TCGETS): %d", errno);
3457c478bd9Sstevel@tonic-gate 		return;
3467c478bd9Sstevel@tonic-gate 	}
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	termios.c_iflag &= ~termios_clear.c_iflag;
3497c478bd9Sstevel@tonic-gate 	termios.c_iflag |= termios_set.c_iflag;
3507c478bd9Sstevel@tonic-gate 	termios.c_oflag &= ~termios_clear.c_oflag;
3517c478bd9Sstevel@tonic-gate 	termios.c_oflag |= termios_set.c_oflag;
3527c478bd9Sstevel@tonic-gate 	termios.c_cflag &= ~termios_clear.c_cflag;
3537c478bd9Sstevel@tonic-gate 	termios.c_cflag |= termios_set.c_cflag;
3547c478bd9Sstevel@tonic-gate 	termios.c_lflag &= ~termios_clear.c_lflag;
3557c478bd9Sstevel@tonic-gate 	termios.c_lflag |= termios_set.c_lflag;
3567c478bd9Sstevel@tonic-gate 
3577c478bd9Sstevel@tonic-gate 	if ((*Ioctl)(fd, TCSETSF, &termios) < 0) {
3587c478bd9Sstevel@tonic-gate 		CDEBUG(5, "ioctl(TCSETSF): %d", errno);
3597c478bd9Sstevel@tonic-gate 		return;
3607c478bd9Sstevel@tonic-gate 	}
3617c478bd9Sstevel@tonic-gate }
362