diff --git a/bin/stty/cchar.c b/bin/stty/cchar.c index 52c3219ac788..ecefbb2bc8f3 100644 --- a/bin/stty/cchar.c +++ b/bin/stty/cchar.c @@ -1,140 +1,139 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)cchar.c 8.5 (Berkeley) 4/2/94"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include "stty.h" #include "extern.h" static int c_cchar(const void *, const void *); /* * Special control characters. * * Cchars1 are the standard names, cchars2 are the old aliases. * The first are displayed, but both are recognized on the * command line. */ struct cchar cchars1[] = { { "discard", VDISCARD, CDISCARD }, { "dsusp", VDSUSP, CDSUSP }, { "eof", VEOF, CEOF }, { "eol", VEOL, CEOL }, { "eol2", VEOL2, CEOL }, { "erase", VERASE, CERASE }, { "erase2", VERASE2, CERASE2 }, { "intr", VINTR, CINTR }, { "kill", VKILL, CKILL }, { "lnext", VLNEXT, CLNEXT }, { "min", VMIN, CMIN }, { "quit", VQUIT, CQUIT }, { "reprint", VREPRINT, CREPRINT }, { "start", VSTART, CSTART }, { "status", VSTATUS, CSTATUS }, { "stop", VSTOP, CSTOP }, { "susp", VSUSP, CSUSP }, { "time", VTIME, CTIME }, { "werase", VWERASE, CWERASE }, { NULL, 0, 0}, }; struct cchar cchars2[] = { { "brk", VEOL, CEOL }, { "flush", VDISCARD, CDISCARD }, { "rprnt", VREPRINT, CREPRINT }, { NULL, 0, 0 }, }; static int c_cchar(const void *a, const void *b) { return (strcmp(((const struct cchar *)a)->name, ((const struct cchar *)b)->name)); } int csearch(char ***argvp, struct info *ip) { struct cchar *cp, tmp; long val; char *arg, *ep, *name; name = **argvp; tmp.name = name; if (!(cp = (struct cchar *)bsearch(&tmp, cchars1, sizeof(cchars1)/sizeof(struct cchar) - 1, sizeof(struct cchar), c_cchar)) && !(cp = (struct cchar *)bsearch(&tmp, cchars2, sizeof(cchars2)/sizeof(struct cchar) - 1, sizeof(struct cchar), c_cchar))) return (0); arg = *++*argvp; if (!arg) { warnx("option requires an argument -- %s", name); usage(); } #define CHK(s) (*arg == s[0] && !strcmp(arg, s)) if (CHK("undef") || CHK("")) ip->t.c_cc[cp->sub] = _POSIX_VDISABLE; else if (cp->sub == VMIN || cp->sub == VTIME) { val = strtol(arg, &ep, 10); if (val > UCHAR_MAX) { warnx("maximum option value is %d -- %s", UCHAR_MAX, name); usage(); } if (*ep != '\0') { warnx("option requires a numeric argument -- %s", name); usage(); } ip->t.c_cc[cp->sub] = val; } else if (arg[0] == '^') ip->t.c_cc[cp->sub] = (arg[1] == '?') ? 0177 : (arg[1] == '-') ? _POSIX_VDISABLE : arg[1] & 037; else ip->t.c_cc[cp->sub] = arg[0]; ip->set = 1; return (1); } diff --git a/bin/stty/key.c b/bin/stty/key.c index 632524305628..4514a0ea1c04 100644 --- a/bin/stty/key.c +++ b/bin/stty/key.c @@ -1,294 +1,293 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)key.c 8.3 (Berkeley) 4/2/94"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include -#include #include #include #include #include "stty.h" #include "extern.h" __BEGIN_DECLS static int c_key(const void *, const void *); void f_all(struct info *); void f_cbreak(struct info *); void f_columns(struct info *); void f_dec(struct info *); void f_ek(struct info *); void f_everything(struct info *); void f_extproc(struct info *); void f_ispeed(struct info *); void f_nl(struct info *); void f_ospeed(struct info *); void f_raw(struct info *); void f_rows(struct info *); void f_sane(struct info *); void f_size(struct info *); void f_speed(struct info *); void f_tty(struct info *); __END_DECLS static struct key { const char *name; /* name */ void (*f)(struct info *); /* function */ #define F_NEEDARG 0x01 /* needs an argument */ #define F_OFFOK 0x02 /* can turn off */ int flags; } keys[] = { { "all", f_all, 0 }, { "cbreak", f_cbreak, F_OFFOK }, { "cols", f_columns, F_NEEDARG }, { "columns", f_columns, F_NEEDARG }, { "cooked", f_sane, 0 }, { "dec", f_dec, 0 }, { "ek", f_ek, 0 }, { "everything", f_everything, 0 }, { "extproc", f_extproc, F_OFFOK }, { "ispeed", f_ispeed, F_NEEDARG }, { "new", f_tty, 0 }, { "nl", f_nl, F_OFFOK }, { "old", f_tty, 0 }, { "ospeed", f_ospeed, F_NEEDARG }, { "raw", f_raw, F_OFFOK }, { "rows", f_rows, F_NEEDARG }, { "sane", f_sane, 0 }, { "size", f_size, 0 }, { "speed", f_speed, 0 }, { "tty", f_tty, 0 }, }; static int c_key(const void *a, const void *b) { return (strcmp(((const struct key *)a)->name, ((const struct key *)b)->name)); } int ksearch(char ***argvp, struct info *ip) { char *name; struct key *kp, tmp; name = **argvp; if (*name == '-') { ip->off = 1; ++name; } else ip->off = 0; tmp.name = name; if (!(kp = (struct key *)bsearch(&tmp, keys, sizeof(keys)/sizeof(struct key), sizeof(struct key), c_key))) return (0); if (!(kp->flags & F_OFFOK) && ip->off) { warnx("illegal option -- -%s", name); usage(); } if (kp->flags & F_NEEDARG && !(ip->arg = *++*argvp)) { warnx("option requires an argument -- %s", name); usage(); } kp->f(ip); return (1); } void f_all(struct info *ip) { print(&ip->t, &ip->win, ip->ldisc, BSD); } void f_cbreak(struct info *ip) { if (ip->off) f_sane(ip); else { ip->t.c_iflag |= BRKINT|IXON|IMAXBEL; ip->t.c_oflag |= OPOST; ip->t.c_lflag |= ISIG|IEXTEN; ip->t.c_lflag &= ~ICANON; ip->set = 1; } } void f_columns(struct info *ip) { ip->win.ws_col = atoi(ip->arg); ip->wset = 1; } void f_dec(struct info *ip) { ip->t.c_cc[VERASE] = (u_char)0177; ip->t.c_cc[VKILL] = CTRL('u'); ip->t.c_cc[VINTR] = CTRL('c'); ip->t.c_lflag &= ~ECHOPRT; ip->t.c_lflag |= ECHOE|ECHOKE|ECHOCTL; ip->t.c_iflag &= ~IXANY; ip->set = 1; } void f_ek(struct info *ip) { ip->t.c_cc[VERASE] = CERASE; ip->t.c_cc[VKILL] = CKILL; ip->set = 1; } void f_everything(struct info *ip) { print(&ip->t, &ip->win, ip->ldisc, BSD); } void f_extproc(struct info *ip) { if (ip->off) { int tmp = 0; (void)ioctl(ip->fd, TIOCEXT, &tmp); } else { int tmp = 1; (void)ioctl(ip->fd, TIOCEXT, &tmp); } } void f_ispeed(struct info *ip) { cfsetispeed(&ip->t, (speed_t)atoi(ip->arg)); ip->set = 1; } void f_nl(struct info *ip) { if (ip->off) { ip->t.c_iflag |= ICRNL; ip->t.c_oflag |= ONLCR; } else { ip->t.c_iflag &= ~ICRNL; ip->t.c_oflag &= ~ONLCR; } ip->set = 1; } void f_ospeed(struct info *ip) { cfsetospeed(&ip->t, (speed_t)atoi(ip->arg)); ip->set = 1; } void f_raw(struct info *ip) { if (ip->off) f_sane(ip); else { cfmakeraw(&ip->t); ip->t.c_cflag &= ~(CSIZE|PARENB); ip->t.c_cflag |= CS8; ip->set = 1; } } void f_rows(struct info *ip) { ip->win.ws_row = atoi(ip->arg); ip->wset = 1; } void f_sane(struct info *ip) { struct termios def; cfmakesane(&def); ip->t.c_cflag = def.c_cflag | (ip->t.c_cflag & CLOCAL); ip->t.c_iflag = def.c_iflag; /* preserve user-preference flags in lflag */ #define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH) ip->t.c_lflag = def.c_lflag | (ip->t.c_lflag & LKEEP); ip->t.c_oflag = def.c_oflag; ip->set = 1; } void f_size(struct info *ip) { (void)printf("%d %d\n", ip->win.ws_row, ip->win.ws_col); } void f_speed(struct info *ip) { (void)printf("%lu\n", (u_long)cfgetospeed(&ip->t)); } void f_tty(struct info *ip) { int tmp; tmp = TTYDISC; if (ioctl(ip->fd, TIOCSETD, &tmp) < 0) err(1, "TIOCSETD"); } diff --git a/bin/stty/modes.c b/bin/stty/modes.c index e34afb83ee38..af24fa018254 100644 --- a/bin/stty/modes.c +++ b/bin/stty/modes.c @@ -1,246 +1,245 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)modes.c 8.3 (Berkeley) 4/2/94"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include -#include #include #include "stty.h" int msearch(char ***, struct info *); struct modes { const char *name; long set; long unset; }; /* * The code in optlist() depends on minus options following regular * options, i.e. "foo" must immediately precede "-foo". */ static const struct modes cmodes[] = { { "cs5", CS5, CSIZE }, { "cs6", CS6, CSIZE }, { "cs7", CS7, CSIZE }, { "cs8", CS8, CSIZE }, { "cstopb", CSTOPB, 0 }, { "-cstopb", 0, CSTOPB }, { "cread", CREAD, 0 }, { "-cread", 0, CREAD }, { "parenb", PARENB, 0 }, { "-parenb", 0, PARENB }, { "parodd", PARODD, 0 }, { "-parodd", 0, PARODD }, { "parity", PARENB | CS7, PARODD | CSIZE }, { "-parity", CS8, PARODD | PARENB | CSIZE }, { "evenp", PARENB | CS7, PARODD | CSIZE }, { "-evenp", CS8, PARODD | PARENB | CSIZE }, { "oddp", PARENB | CS7 | PARODD, CSIZE }, { "-oddp", CS8, PARODD | PARENB | CSIZE }, { "pass8", CS8, PARODD | PARENB | CSIZE }, { "-pass8", PARENB | CS7, PARODD | CSIZE }, { "hupcl", HUPCL, 0 }, { "-hupcl", 0, HUPCL }, { "hup", HUPCL, 0 }, { "-hup", 0, HUPCL }, { "clocal", CLOCAL, 0 }, { "-clocal", 0, CLOCAL }, { "crtscts", CRTSCTS, 0 }, { "-crtscts", 0, CRTSCTS }, { "ctsflow", CCTS_OFLOW, 0 }, { "-ctsflow", 0, CCTS_OFLOW }, { "dsrflow", CDSR_OFLOW, 0 }, { "-dsrflow", 0, CDSR_OFLOW }, { "dtrflow", CDTR_IFLOW, 0 }, { "-dtrflow", 0, CDTR_IFLOW }, { "rtsflow", CRTS_IFLOW, 0 }, { "-rtsflow", 0, CRTS_IFLOW }, { "mdmbuf", MDMBUF, 0 }, { "-mdmbuf", 0, MDMBUF }, { NULL, 0, 0 }, }; static const struct modes imodes[] = { { "ignbrk", IGNBRK, 0 }, { "-ignbrk", 0, IGNBRK }, { "brkint", BRKINT, 0 }, { "-brkint", 0, BRKINT }, { "ignpar", IGNPAR, 0 }, { "-ignpar", 0, IGNPAR }, { "parmrk", PARMRK, 0 }, { "-parmrk", 0, PARMRK }, { "inpck", INPCK, 0 }, { "-inpck", 0, INPCK }, { "istrip", ISTRIP, 0 }, { "-istrip", 0, ISTRIP }, { "inlcr", INLCR, 0 }, { "-inlcr", 0, INLCR }, { "igncr", IGNCR, 0 }, { "-igncr", 0, IGNCR }, { "icrnl", ICRNL, 0 }, { "-icrnl", 0, ICRNL }, { "ixon", IXON, 0 }, { "-ixon", 0, IXON }, { "flow", IXON, 0 }, { "-flow", 0, IXON }, { "ixoff", IXOFF, 0 }, { "-ixoff", 0, IXOFF }, { "tandem", IXOFF, 0 }, { "-tandem", 0, IXOFF }, { "ixany", IXANY, 0 }, { "-ixany", 0, IXANY }, { "decctlq", 0, IXANY }, { "-decctlq", IXANY, 0 }, { "imaxbel", IMAXBEL, 0 }, { "-imaxbel", 0, IMAXBEL }, { NULL, 0, 0 }, }; static const struct modes lmodes[] = { { "echo", ECHO, 0 }, { "-echo", 0, ECHO }, { "echoe", ECHOE, 0 }, { "-echoe", 0, ECHOE }, { "crterase", ECHOE, 0 }, { "-crterase", 0, ECHOE }, { "crtbs", ECHOE, 0 }, /* crtbs not supported, close enough */ { "-crtbs", 0, ECHOE }, { "echok", ECHOK, 0 }, { "-echok", 0, ECHOK }, { "echoke", ECHOKE, 0 }, { "-echoke", 0, ECHOKE }, { "crtkill", ECHOKE, 0 }, { "-crtkill", 0, ECHOKE }, { "altwerase", ALTWERASE, 0 }, { "-altwerase", 0, ALTWERASE }, { "iexten", IEXTEN, 0 }, { "-iexten", 0, IEXTEN }, { "echonl", ECHONL, 0 }, { "-echonl", 0, ECHONL }, { "echoctl", ECHOCTL, 0 }, { "-echoctl", 0, ECHOCTL }, { "ctlecho", ECHOCTL, 0 }, { "-ctlecho", 0, ECHOCTL }, { "echoprt", ECHOPRT, 0 }, { "-echoprt", 0, ECHOPRT }, { "prterase", ECHOPRT, 0 }, { "-prterase", 0, ECHOPRT }, { "isig", ISIG, 0 }, { "-isig", 0, ISIG }, { "icanon", ICANON, 0 }, { "-icanon", 0, ICANON }, { "noflsh", NOFLSH, 0 }, { "-noflsh", 0, NOFLSH }, { "tostop", TOSTOP, 0 }, { "-tostop", 0, TOSTOP }, { "flusho", FLUSHO, 0 }, { "-flusho", 0, FLUSHO }, { "pendin", PENDIN, 0 }, { "-pendin", 0, PENDIN }, { "crt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, { "-crt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, { "newcrt", ECHOE|ECHOKE|ECHOCTL, ECHOK|ECHOPRT }, { "-newcrt", ECHOK, ECHOE|ECHOKE|ECHOCTL }, { "nokerninfo", NOKERNINFO, 0 }, { "-nokerninfo",0, NOKERNINFO }, { "kerninfo", 0, NOKERNINFO }, { "-kerninfo", NOKERNINFO, 0 }, { NULL, 0, 0 }, }; static const struct modes omodes[] = { { "opost", OPOST, 0 }, { "-opost", 0, OPOST }, { "litout", 0, OPOST }, { "-litout", OPOST, 0 }, { "onlcr", ONLCR, 0 }, { "-onlcr", 0, ONLCR }, { "ocrnl", OCRNL, 0 }, { "-ocrnl", 0, OCRNL }, { "tabs", TAB0, TABDLY }, /* "preserve" tabs */ { "-tabs", TAB3, TABDLY }, { "oxtabs", TAB3, TABDLY }, { "-oxtabs", TAB0, TABDLY }, { "tab0", TAB0, TABDLY }, { "tab3", TAB3, TABDLY }, { "onocr", ONOCR, 0 }, { "-onocr", 0, ONOCR }, { "onlret", ONLRET, 0 }, { "-onlret", 0, ONLRET }, { NULL, 0, 0 }, }; #define CHK(s) (*name == s[0] && !strcmp(name, s)) int msearch(char ***argvp, struct info *ip) { const struct modes *mp; char *name; name = **argvp; for (mp = cmodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_cflag &= ~mp->unset; ip->t.c_cflag |= mp->set; ip->set = 1; return (1); } for (mp = imodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_iflag &= ~mp->unset; ip->t.c_iflag |= mp->set; ip->set = 1; return (1); } for (mp = lmodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_lflag &= ~mp->unset; ip->t.c_lflag |= mp->set; ip->set = 1; return (1); } for (mp = omodes; mp->name; ++mp) if (CHK(mp->name)) { ip->t.c_oflag &= ~mp->unset; ip->t.c_oflag |= mp->set; ip->set = 1; return (1); } return (0); } diff --git a/bin/stty/stty.c b/bin/stty/stty.c index 234008329c0a..9aa2f51aa81f 100644 --- a/bin/stty/stty.c +++ b/bin/stty/stty.c @@ -1,167 +1,166 @@ /*- * Copyright (c) 1989, 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #if 0 #ifndef lint static char const copyright[] = "@(#) Copyright (c) 1989, 1991, 1993, 1994\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint static char sccsid[] = "@(#)stty.c 8.3 (Berkeley) 4/2/94"; #endif /* not lint */ #endif #include __FBSDID("$FreeBSD$"); #include #include #include -#include #include #include #include #include #include #include #include "stty.h" #include "extern.h" int main(int argc, char *argv[]) { struct info i; enum FMT fmt; int ch; const char *file, *errstr = NULL; fmt = NOTSET; i.fd = STDIN_FILENO; file = "stdin"; opterr = 0; while (optind < argc && strspn(argv[optind], "-aefg") == strlen(argv[optind]) && (ch = getopt(argc, argv, "aef:g")) != -1) switch(ch) { case 'a': /* undocumented: POSIX compatibility */ fmt = POSIX; break; case 'e': fmt = BSD; break; case 'f': if ((i.fd = open(optarg, O_RDONLY | O_NONBLOCK)) < 0) err(1, "%s", optarg); file = optarg; break; case 'g': fmt = GFLAG; break; case '?': default: goto args; } args: argc -= optind; argv += optind; if (tcgetattr(i.fd, &i.t) < 0) errx(1, "%s isn't a terminal", file); if (ioctl(i.fd, TIOCGETD, &i.ldisc) < 0) err(1, "TIOCGETD"); if (ioctl(i.fd, TIOCGWINSZ, &i.win) < 0) warn("TIOCGWINSZ"); checkredirect(); /* conversion aid */ switch(fmt) { case NOTSET: if (*argv) break; /* FALLTHROUGH */ case BSD: case POSIX: print(&i.t, &i.win, i.ldisc, fmt); break; case GFLAG: gprint(&i.t, &i.win, i.ldisc); break; } for (i.set = i.wset = 0; *argv; ++argv) { if (ksearch(&argv, &i)) continue; if (csearch(&argv, &i)) continue; if (msearch(&argv, &i)) continue; if (isdigit(**argv)) { speed_t speed; speed = strtonum(*argv, 0, UINT_MAX, &errstr); if (errstr) err(1, "speed"); cfsetospeed(&i.t, speed); cfsetispeed(&i.t, speed); i.set = 1; continue; } if (!strncmp(*argv, "gfmt1", sizeof("gfmt1") - 1)) { gread(&i.t, *argv + sizeof("gfmt1") - 1); i.set = 1; continue; } warnx("illegal option -- %s", *argv); usage(); } if (i.set && tcsetattr(i.fd, 0, &i.t) < 0) err(1, "tcsetattr"); if (i.wset && ioctl(i.fd, TIOCSWINSZ, &i.win) < 0) warn("TIOCSWINSZ"); exit(0); } void usage(void) { (void)fprintf(stderr, "usage: stty [-a | -e | -g] [-f file] [arguments]\n"); exit (1); } diff --git a/bin/stty/util.c b/bin/stty/util.c index 8c2755820d8d..19898ba9805f 100644 --- a/bin/stty/util.c +++ b/bin/stty/util.c @@ -1,64 +1,62 @@ /*- * Copyright (c) 1991, 1993, 1994 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #ifndef lint #if 0 static char sccsid[] = "@(#)util.c 8.3 (Berkeley) 4/2/94"; #endif #endif /* not lint */ #include __FBSDID("$FreeBSD$"); #include #include #include -#include -#include #include #include "stty.h" #include "extern.h" /* * Gross, but since we're changing the control descriptor from 1 to 0, most * users will be probably be doing "stty > /dev/sometty" by accident. If 1 * and 2 are both ttys, but not the same, assume that 1 was incorrectly * redirected. */ void checkredirect(void) { struct stat sb1, sb2; if (isatty(STDOUT_FILENO) && isatty(STDERR_FILENO) && !fstat(STDOUT_FILENO, &sb1) && !fstat(STDERR_FILENO, &sb2) && (sb1.st_rdev != sb2.st_rdev)) warnx("stdout appears redirected, but stdin is the control descriptor"); }