SCCS-vsn: bin/stty/stty.c 5.26
#endif /* not lint */
#ifndef lint
#endif /* not lint */
#ifndef lint
-static char sccsid[] = "@(#)stty.c 5.25 (Berkeley) %G%";
+static char sccsid[] = "@(#)stty.c 5.26 (Berkeley) %G%";
#endif /* not lint */
#include <sys/types.h>
#endif /* not lint */
#include <sys/types.h>
struct winsize win;
struct termios t;
enum FMT fmt;
struct winsize win;
struct termios t;
enum FMT fmt;
- int ch, ctl, ldisc, tmp;
+ int ch, ctl, ldisc, set, tmp, wset;
ctl = STDIN_FILENO;
fmt = NOTSET;
ctl = STDIN_FILENO;
fmt = NOTSET;
#define CHK(s) (**argv == s[0] && !strcmp(*argv, s))
#define CHK(s) (**argv == s[0] && !strcmp(*argv, s))
- for (; *argv; ++argv) {
+ for (set = wset = 0; *argv; ++argv) {
if (CHK("-nl")) {
t.c_iflag |= ICRNL;
t.c_oflag |= ONLCR;
if (CHK("-nl")) {
t.c_iflag |= ICRNL;
t.c_oflag |= ONLCR;
continue;
}
if (CHK("all")) {
continue;
}
if (CHK("all")) {
t.c_oflag |= OPOST;
t.c_lflag |= ISIG|IEXTEN;
t.c_lflag &= ~ICANON;
t.c_oflag |= OPOST;
t.c_lflag |= ISIG|IEXTEN;
t.c_lflag &= ~ICANON;
continue;
}
if (CHK("cols")) {
continue;
}
if (CHK("cols")) {
if (!*++argv)
err("option requires an argument -- columns");
columns: win.ws_col = atoi(*argv);
if (!*++argv)
err("option requires an argument -- columns");
columns: win.ws_col = atoi(*argv);
continue;
}
if (CHK("cooked"))
continue;
}
if (CHK("cooked"))
t.c_lflag &= ~ECHOPRT;
t.c_lflag |= ECHOE|ECHOKE|ECHOCTL;
t.c_iflag &= ~IXANY;
t.c_lflag &= ~ECHOPRT;
t.c_lflag |= ECHOE|ECHOKE|ECHOCTL;
t.c_iflag &= ~IXANY;
continue;
}
if (CHK("everything")) {
continue;
}
if (CHK("everything")) {
ioctl(ctl, TIOCEXT, &tmp);
continue;
}
ioctl(ctl, TIOCEXT, &tmp);
continue;
}
tmp = 1;
ioctl(ctl, TIOCEXT, &tmp);
continue;
tmp = 1;
ioctl(ctl, TIOCEXT, &tmp);
continue;
if (!*++argv)
err("option requires an argument -- ispeed");
cfsetispeed(&t, atoi(*argv));
if (!*++argv)
err("option requires an argument -- ispeed");
cfsetispeed(&t, atoi(*argv));
continue;
}
if (CHK("new"))
continue;
}
if (CHK("new"))
if (CHK("nl")) {
t.c_iflag &= ~ICRNL;
t.c_oflag &= ~ONLCR;
if (CHK("nl")) {
t.c_iflag &= ~ICRNL;
t.c_oflag &= ~ONLCR;
continue;
}
if (CHK("old"))
continue;
}
if (CHK("old"))
if (!*++argv)
err("option requires an argument -- ospeed");
cfsetospeed(&t, atoi(*argv));
if (!*++argv)
err("option requires an argument -- ospeed");
cfsetospeed(&t, atoi(*argv));
continue;
}
if (CHK("-raw"))
continue;
}
if (CHK("-raw"))
cfmakeraw(&t);
t.c_cflag &= ~(CSIZE|PARENB);
t.c_cflag |= CS8;
cfmakeraw(&t);
t.c_cflag &= ~(CSIZE|PARENB);
t.c_cflag |= CS8;
continue;
}
if (CHK("rows")) {
if (!*++argv)
err("option requires an argument -- rows");
win.ws_row = atoi(*argv);
continue;
}
if (CHK("rows")) {
if (!*++argv)
err("option requires an argument -- rows");
win.ws_row = atoi(*argv);
continue;
}
if (CHK("sane")) {
continue;
}
if (CHK("sane")) {
#define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH)
t.c_lflag = TTYDEF_LFLAG | (t.c_lflag & LKEEP);
t.c_oflag = TTYDEF_OFLAG;
#define LKEEP (ECHOKE|ECHOE|ECHOK|ECHOPRT|ECHOCTL|ALTWERASE|TOSTOP|NOFLSH)
t.c_lflag = TTYDEF_LFLAG | (t.c_lflag & LKEEP);
t.c_oflag = TTYDEF_OFLAG;
continue;
}
if (CHK("size")) {
continue;
}
if (CHK("size")) {
if (CHK(mp->name)) {
t.c_cflag &= ~mp->unset;
t.c_cflag |= mp->set;
if (CHK(mp->name)) {
t.c_cflag &= ~mp->unset;
t.c_cflag |= mp->set;
goto next;
}
for (mp = imodes; mp->name; ++mp)
if (CHK(mp->name)) {
t.c_iflag &= ~mp->unset;
t.c_iflag |= mp->set;
goto next;
}
for (mp = imodes; mp->name; ++mp)
if (CHK(mp->name)) {
t.c_iflag &= ~mp->unset;
t.c_iflag |= mp->set;
goto next;
}
for (mp = lmodes; mp->name; ++mp)
if (CHK(mp->name)) {
t.c_lflag &= ~mp->unset;
t.c_lflag |= mp->set;
goto next;
}
for (mp = lmodes; mp->name; ++mp)
if (CHK(mp->name)) {
t.c_lflag &= ~mp->unset;
t.c_lflag |= mp->set;
goto next;
}
for (mp = omodes; mp->name; ++mp)
if (CHK(mp->name)) {
t.c_oflag &= ~mp->unset;
t.c_oflag |= mp->set;
goto next;
}
for (mp = omodes; mp->name; ++mp)
if (CHK(mp->name)) {
t.c_oflag &= ~mp->unset;
t.c_oflag |= mp->set;
goto next;
}
for (cp = cchars1; cp->name; ++cp) {
goto next;
}
for (cp = cchars1; cp->name; ++cp) {
(*argv)[1] & 037;
else
t.c_cc[cp->sub] = **argv;
(*argv)[1] & 037;
else
t.c_cc[cp->sub] = **argv;
- if (tcsetattr(ctl, 0, &t) < 0)
+ if (set && tcsetattr(ctl, 0, &t) < 0)
err("tcsetattr: %s", strerror(errno));
err("tcsetattr: %s", strerror(errno));
- if (ioctl(ctl, TIOCSWINSZ, &win) < 0)
+ if (wset && ioctl(ctl, TIOCSWINSZ, &win) < 0)
warn("TIOCSWINSZ: %s", strerror(errno));
exit(0);
}
warn("TIOCSWINSZ: %s", strerror(errno));
exit(0);
}