11556Srgrimes/*- 21556Srgrimes * Copyright (c) 1991, 1993, 1994 31556Srgrimes * The Regents of the University of California. All rights reserved. 41556Srgrimes * 51556Srgrimes * Redistribution and use in source and binary forms, with or without 61556Srgrimes * modification, are permitted provided that the following conditions 71556Srgrimes * are met: 81556Srgrimes * 1. Redistributions of source code must retain the above copyright 91556Srgrimes * notice, this list of conditions and the following disclaimer. 101556Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111556Srgrimes * notice, this list of conditions and the following disclaimer in the 121556Srgrimes * documentation and/or other materials provided with the distribution. 131556Srgrimes * 4. Neither the name of the University nor the names of its contributors 141556Srgrimes * may be used to endorse or promote products derived from this software 151556Srgrimes * without specific prior written permission. 161556Srgrimes * 171556Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 181556Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 191556Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 201556Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 211556Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 221556Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 231556Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 241556Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 251556Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 261556Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 271556Srgrimes * SUCH DAMAGE. 281556Srgrimes */ 291556Srgrimes 301556Srgrimes#ifndef lint 3136152Scharnier#if 0 3236152Scharnierstatic char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94"; 3336152Scharnier#endif 341556Srgrimes#endif /* not lint */ 3599110Sobrien#include <sys/cdefs.h> 3699110Sobrien__FBSDID("$FreeBSD$"); 371556Srgrimes 381556Srgrimes#include <sys/types.h> 391556Srgrimes#include <stddef.h> 401556Srgrimes#include <string.h> 411556Srgrimes#include "stty.h" 421556Srgrimes 4390111Simpint msearch(char ***, struct info *); 4476810Skris 451556Srgrimesstruct modes { 4676810Skris const char *name; 471556Srgrimes long set; 481556Srgrimes long unset; 491556Srgrimes}; 501556Srgrimes 511556Srgrimes/* 521556Srgrimes * The code in optlist() depends on minus options following regular 531556Srgrimes * options, i.e. "foo" must immediately precede "-foo". 541556Srgrimes */ 55228406Sedstatic const struct modes cmodes[] = { 561556Srgrimes { "cs5", CS5, CSIZE }, 571556Srgrimes { "cs6", CS6, CSIZE }, 581556Srgrimes { "cs7", CS7, CSIZE }, 591556Srgrimes { "cs8", CS8, CSIZE }, 601556Srgrimes { "cstopb", CSTOPB, 0 }, 611556Srgrimes { "-cstopb", 0, CSTOPB }, 621556Srgrimes { "cread", CREAD, 0 }, 631556Srgrimes { "-cread", 0, CREAD }, 641556Srgrimes { "parenb", PARENB, 0 }, 651556Srgrimes { "-parenb", 0, PARENB }, 661556Srgrimes { "parodd", PARODD, 0 }, 671556Srgrimes { "-parodd", 0, PARODD }, 681556Srgrimes { "parity", PARENB | CS7, PARODD | CSIZE }, 691556Srgrimes { "-parity", CS8, PARODD | PARENB | CSIZE }, 701556Srgrimes { "evenp", PARENB | CS7, PARODD | CSIZE }, 711556Srgrimes { "-evenp", CS8, PARODD | PARENB | CSIZE }, 721556Srgrimes { "oddp", PARENB | CS7 | PARODD, CSIZE }, 731556Srgrimes { "-oddp", CS8, PARODD | PARENB | CSIZE }, 741556Srgrimes { "pass8", CS8, PARODD | PARENB | CSIZE }, 751556Srgrimes { "-pass8", PARENB | CS7, PARODD | CSIZE }, 761556Srgrimes { "hupcl", HUPCL, 0 }, 771556Srgrimes { "-hupcl", 0, HUPCL }, 781556Srgrimes { "hup", HUPCL, 0 }, 791556Srgrimes { "-hup", 0, HUPCL }, 801556Srgrimes { "clocal", CLOCAL, 0 }, 811556Srgrimes { "-clocal", 0, CLOCAL }, 821556Srgrimes { "crtscts", CRTSCTS, 0 }, 831556Srgrimes { "-crtscts", 0, CRTSCTS }, 848170Sbde { "ctsflow", CCTS_OFLOW, 0 }, 858170Sbde { "-ctsflow", 0, CCTS_OFLOW }, 868170Sbde { "dsrflow", CDSR_OFLOW, 0 }, 878170Sbde { "-dsrflow", 0, CDSR_OFLOW }, 888170Sbde { "dtrflow", CDTR_IFLOW, 0 }, 898170Sbde { "-dtrflow", 0, CDTR_IFLOW }, 908170Sbde { "rtsflow", CRTS_IFLOW, 0 }, 918170Sbde { "-rtsflow", 0, CRTS_IFLOW }, 921556Srgrimes { "mdmbuf", MDMBUF, 0 }, 931556Srgrimes { "-mdmbuf", 0, MDMBUF }, 9476810Skris { NULL, 0, 0 }, 951556Srgrimes}; 961556Srgrimes 97228406Sedstatic const struct modes imodes[] = { 981556Srgrimes { "ignbrk", IGNBRK, 0 }, 991556Srgrimes { "-ignbrk", 0, IGNBRK }, 1001556Srgrimes { "brkint", BRKINT, 0 }, 1011556Srgrimes { "-brkint", 0, BRKINT }, 1021556Srgrimes { "ignpar", IGNPAR, 0 }, 1031556Srgrimes { "-ignpar", 0, IGNPAR }, 1041556Srgrimes { "parmrk", PARMRK, 0 }, 1051556Srgrimes { "-parmrk", 0, PARMRK }, 1061556Srgrimes { "inpck", INPCK, 0 }, 1071556Srgrimes { "-inpck", 0, INPCK }, 1081556Srgrimes { "istrip", ISTRIP, 0 }, 1091556Srgrimes { "-istrip", 0, ISTRIP }, 1101556Srgrimes { "inlcr", INLCR, 0 }, 1111556Srgrimes { "-inlcr", 0, INLCR }, 1121556Srgrimes { "igncr", IGNCR, 0 }, 1131556Srgrimes { "-igncr", 0, IGNCR }, 1141556Srgrimes { "icrnl", ICRNL, 0 }, 1151556Srgrimes { "-icrnl", 0, ICRNL }, 1161556Srgrimes { "ixon", IXON, 0 }, 1171556Srgrimes { "-ixon", 0, IXON }, 1181556Srgrimes { "flow", IXON, 0 }, 1191556Srgrimes { "-flow", 0, IXON }, 1201556Srgrimes { "ixoff", IXOFF, 0 }, 1211556Srgrimes { "-ixoff", 0, IXOFF }, 1221556Srgrimes { "tandem", IXOFF, 0 }, 1231556Srgrimes { "-tandem", 0, IXOFF }, 1241556Srgrimes { "ixany", IXANY, 0 }, 1251556Srgrimes { "-ixany", 0, IXANY }, 1261556Srgrimes { "decctlq", 0, IXANY }, 1271556Srgrimes { "-decctlq", IXANY, 0 }, 1281556Srgrimes { "imaxbel", IMAXBEL, 0 }, 1291556Srgrimes { "-imaxbel", 0, IMAXBEL }, 13076810Skris { NULL, 0, 0 }, 1311556Srgrimes}; 1321556Srgrimes 133228406Sedstatic const struct modes lmodes[] = { 1341556Srgrimes { "echo", ECHO, 0 }, 1351556Srgrimes { "-echo", 0, ECHO }, 1361556Srgrimes { "echoe", ECHOE, 0 }, 1371556Srgrimes { "-echoe", 0, ECHOE }, 1381556Srgrimes { "crterase", ECHOE, 0 }, 1391556Srgrimes { "-crterase", 0, ECHOE }, 1401556Srgrimes { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */ 1411556Srgrimes { "-crtbs", 0, ECHOE }, 1421556Srgrimes { "echok", ECHOK, 0 }, 1431556Srgrimes { "-echok", 0, ECHOK }, 1441556Srgrimes { "echoke", ECHOKE, 0 }, 1451556Srgrimes { "-echoke", 0, ECHOKE }, 1461556Srgrimes { "crtkill", ECHOKE, 0 }, 1471556Srgrimes { "-crtkill", 0, ECHOKE }, 1481556Srgrimes { "altwerase", ALTWERASE, 0 }, 1491556Srgrimes { "-altwerase", 0, ALTWERASE }, 1501556Srgrimes { "iexten", IEXTEN, 0 }, 1511556Srgrimes { "-iexten", 0, IEXTEN }, 1521556Srgrimes { "echonl", ECHONL, 0 }, 1531556Srgrimes { "-echonl", 0, ECHONL }, 1541556Srgrimes { "echoctl", ECHOCTL, 0 }, 1551556Srgrimes { "-echoctl", 0, ECHOCTL }, 1561556Srgrimes { "ctlecho", ECHOCTL, 0 }, 1571556Srgrimes { "-ctlecho", 0, ECHOCTL }, 1581556Srgrimes { "echoprt", ECHOPRT, 0 }, 1591556Srgrimes { "-echoprt", 0, ECHOPRT }, 1601556Srgrimes { "prterase", ECHOPRT, 0 }, 1611556Srgrimes { "-prterase", 0, ECHOPRT }, 1621556Srgrimes { "isig", ISIG, 0 }, 1631556Srgrimes { "-isig", 0, ISIG }, 1641556Srgrimes { "icanon", ICANON, 0 }, 1651556Srgrimes { "-icanon", 0, ICANON }, 1661556Srgrimes { "noflsh", NOFLSH, 0 }, 1671556Srgrimes { "-noflsh", 0, NOFLSH }, 1681556Srgrimes { "tostop", TOSTOP, 0 }, 1691556Srgrimes { "-tostop", 0, TOSTOP }, 1701556Srgrimes { "flusho", FLUSHO, 0 }, 1711556Srgrimes { "-flusho", 0, FLUSHO }, 1721556Srgrimes { "pendin", PENDIN, 0 }, 1731556Srgrimes { "-pendin", 0, PENDIN }, 1741556Srgrimes { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, 1751556Srgrimes { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, 1761556Srgrimes { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, 1771556Srgrimes { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, 1781556Srgrimes { "nokerninfo", NOKERNINFO, 0 }, 1791556Srgrimes { "-nokerninfo",0, NOKERNINFO }, 1801556Srgrimes { "kerninfo", 0, NOKERNINFO }, 1811556Srgrimes { "-kerninfo", NOKERNINFO, 0 }, 18276810Skris { NULL, 0, 0 }, 1831556Srgrimes}; 1841556Srgrimes 185228406Sedstatic const struct modes omodes[] = { 1861556Srgrimes { "opost", OPOST, 0 }, 1871556Srgrimes { "-opost", 0, OPOST }, 1881556Srgrimes { "litout", 0, OPOST }, 1891556Srgrimes { "-litout", OPOST, 0 }, 1901556Srgrimes { "onlcr", ONLCR, 0 }, 1911556Srgrimes { "-onlcr", 0, ONLCR }, 19273421Sassar { "ocrnl", OCRNL, 0 }, 19373421Sassar { "-ocrnl", 0, OCRNL }, 194182052Sed { "tabs", TAB0, TABDLY }, /* "preserve" tabs */ 195182052Sed { "-tabs", TAB3, TABDLY }, 196182052Sed { "oxtabs", TAB3, TABDLY }, 197182052Sed { "-oxtabs", TAB0, TABDLY }, 198182052Sed { "tab0", TAB0, TABDLY }, 199182052Sed { "tab3", TAB3, TABDLY }, 20073421Sassar { "onocr", ONOCR, 0 }, 20173421Sassar { "-onocr", 0, ONOCR }, 20273421Sassar { "onlret", ONLRET, 0 }, 20373421Sassar { "-onlret", 0, ONLRET }, 20476810Skris { NULL, 0, 0 }, 2051556Srgrimes}; 2061556Srgrimes 2071556Srgrimes#define CHK(s) (*name == s[0] && !strcmp(name, s)) 2081556Srgrimes 2091556Srgrimesint 21090111Simpmsearch(char ***argvp, struct info *ip) 2111556Srgrimes{ 212228406Sed const struct modes *mp; 2131556Srgrimes char *name; 2141556Srgrimes 2151556Srgrimes name = **argvp; 2161556Srgrimes 2171556Srgrimes for (mp = cmodes; mp->name; ++mp) 2181556Srgrimes if (CHK(mp->name)) { 2191556Srgrimes ip->t.c_cflag &= ~mp->unset; 2201556Srgrimes ip->t.c_cflag |= mp->set; 2211556Srgrimes ip->set = 1; 2221556Srgrimes return (1); 2231556Srgrimes } 2241556Srgrimes for (mp = imodes; mp->name; ++mp) 2251556Srgrimes if (CHK(mp->name)) { 2261556Srgrimes ip->t.c_iflag &= ~mp->unset; 2271556Srgrimes ip->t.c_iflag |= mp->set; 2281556Srgrimes ip->set = 1; 2291556Srgrimes return (1); 2301556Srgrimes } 2311556Srgrimes for (mp = lmodes; mp->name; ++mp) 2321556Srgrimes if (CHK(mp->name)) { 2331556Srgrimes ip->t.c_lflag &= ~mp->unset; 2341556Srgrimes ip->t.c_lflag |= mp->set; 2351556Srgrimes ip->set = 1; 2361556Srgrimes return (1); 2371556Srgrimes } 2381556Srgrimes for (mp = omodes; mp->name; ++mp) 2391556Srgrimes if (CHK(mp->name)) { 2401556Srgrimes ip->t.c_oflag &= ~mp->unset; 2411556Srgrimes ip->t.c_oflag |= mp->set; 2421556Srgrimes ip->set = 1; 2431556Srgrimes return (1); 2441556Srgrimes } 2451556Srgrimes return (0); 2461556Srgrimes} 247