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