Fix numerous bugs; flags in the wrong places, modes getting clobbered, etc.

This commit is contained in:
mycroft 1994-04-12 17:18:59 +00:00
parent de318bb111
commit 2566987063
1 changed files with 43 additions and 40 deletions

View File

@ -31,7 +31,7 @@
* SUCH DAMAGE. * SUCH DAMAGE.
* *
* from: @(#)tty_compat.c 7.10 (Berkeley) 5/9/91 * from: @(#)tty_compat.c 7.10 (Berkeley) 5/9/91
* $Id: tty_compat.c,v 1.11 1994/03/05 22:42:55 mycroft Exp $ * $Id: tty_compat.c,v 1.12 1994/04/12 17:18:59 mycroft Exp $
*/ */
/* /*
@ -42,12 +42,11 @@
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <sys/proc.h>
#include <sys/tty.h> #include <sys/tty.h>
#include <sys/termios.h> #include <sys/termios.h>
#include <sys/proc.h>
#include <sys/file.h> #include <sys/file.h>
#include <sys/conf.h> #include <sys/conf.h>
#include <sys/dkstat.h>
#include <sys/kernel.h> #include <sys/kernel.h>
#include <sys/syslog.h> #include <sys/syslog.h>
@ -110,7 +109,7 @@ ttcompat(tp, com, data, flag, p)
} }
sg->sg_erase = cc[VERASE]; sg->sg_erase = cc[VERASE];
sg->sg_kill = cc[VKILL]; sg->sg_kill = cc[VKILL];
sg->sg_flags = tp->t_flags = ttcompatgetflags(tp); sg->sg_flags = ttcompatgetflags(tp);
break; break;
} }
@ -131,7 +130,7 @@ ttcompat(tp, com, data, flag, p)
term.c_ospeed = compatspcodes[speed]; term.c_ospeed = compatspcodes[speed];
term.c_cc[VERASE] = sg->sg_erase; term.c_cc[VERASE] = sg->sg_erase;
term.c_cc[VKILL] = sg->sg_kill; term.c_cc[VKILL] = sg->sg_kill;
tp->t_flags = ttcompatgetflags(tp)&0xffff0000 | sg->sg_flags&0xffff; tp->t_flags = tp->t_flags&0xffff0000 | sg->sg_flags&0xffff;
ttcompatsetflags(tp, &term); ttcompatsetflags(tp, &term);
return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA, return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA,
(caddr_t)&term, flag, p)); (caddr_t)&term, flag, p));
@ -194,9 +193,10 @@ ttcompat(tp, com, data, flag, p)
term = tp->t_termios; term = tp->t_termios;
if (com == TIOCLSET) if (com == TIOCLSET)
tp->t_flags = (ttcompatgetflags(tp)&0xffff) | *(int *)data<<16; tp->t_flags = (tp->t_flags&0xffff) | *(int *)data<<16;
else { else {
tp->t_flags = ttcompatgetflags(tp); tp->t_flags =
(ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
if (com == TIOCLBIS) if (com == TIOCLBIS)
tp->t_flags |= *(int *)data<<16; tp->t_flags |= *(int *)data<<16;
else else
@ -206,9 +206,7 @@ ttcompat(tp, com, data, flag, p)
return (ttioctl(tp, TIOCSETA, (caddr_t)&term, flag, p)); return (ttioctl(tp, TIOCSETA, (caddr_t)&term, flag, p));
} }
case TIOCLGET: case TIOCLGET:
tp->t_flags = *(int *)data = ttcompatgetflags(tp)>>16;
(ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
*(int *)data = tp->t_flags>>16;
if (ttydebug) if (ttydebug)
printf("CLGET: returning %x\n", *(int *)data); printf("CLGET: returning %x\n", *(int *)data);
break; break;
@ -253,12 +251,7 @@ ttcompatgetflags(tp)
flags |= TANDEM; flags |= TANDEM;
if (iflag&ICRNL || oflag&ONLCR) if (iflag&ICRNL || oflag&ONLCR)
flags |= CRMOD; flags |= CRMOD;
if ((cflag&CSIZE) == CS8) { if (cflag&PARENB) {
flags |= PASS8;
if (iflag&ISTRIP)
flags |= ANYP;
}
else if (cflag&PARENB) {
if (iflag&INPCK) { if (iflag&INPCK) {
if (cflag&PARODD) if (cflag&PARODD)
flags |= ODDP; flags |= ODDP;
@ -266,17 +259,24 @@ ttcompatgetflags(tp)
flags |= EVENP; flags |= EVENP;
} else } else
flags |= EVENP | ODDP; flags |= EVENP | ODDP;
} else {
if ((tp->t_flags&LITOUT) && !(oflag&OPOST))
flags |= LITOUT;
if (tp->t_flags&PASS8)
flags |= PASS8;
} }
if ((lflag&ICANON) == 0) { if ((lflag&ICANON) == 0) {
/* fudge */ /* fudge */
if (oflag&OPOST || iflag&ISTRIP || iflag&IXON || lflag&ISIG || lflag&IEXTEN || cflag&PARENB || iflag&INPCK || (cflag&CSIZE) != CS8) if (iflag&IXON || lflag&ISIG || lflag&IEXTEN || cflag&PARENB)
flags |= CBREAK; flags |= CBREAK;
else else
flags |= RAW; flags |= RAW;
} }
if (!(flags&RAW) && !(oflag&OPOST) && (!(cflag&PARENB) || (cflag&CSIZE) == CS8)) if (cflag&MDMBUF)
flags |= LITOUT; flags |= MDMBUF;
if ((cflag&HUPCL) == 0)
flags |= NOHANG;
if (oflag&OXTABS) if (oflag&OXTABS)
flags |= XTABS; flags |= XTABS;
if (lflag&ECHOE) if (lflag&ECHOE)
@ -289,9 +289,9 @@ ttcompatgetflags(tp)
flags |= CTLECH; flags |= CTLECH;
if ((iflag&IXANY) == 0) if ((iflag&IXANY) == 0)
flags |= DECCTQ; flags |= DECCTQ;
flags |= lflag&(ECHO|MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH); flags |= lflag&(ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH);
if (ttydebug) if (ttydebug)
printf("getflags: %x\n", flags); printf("getflags: %x\n", flags);
return (flags); return (flags);
} }
@ -307,7 +307,7 @@ ttcompatsetflags(tp, t)
register long cflag = t->c_cflag; register long cflag = t->c_cflag;
if (flags & RAW) { if (flags & RAW) {
iflag &= (IXOFF|IXANY); iflag &= IXOFF;
oflag &= ~OPOST; oflag &= ~OPOST;
lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN); lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN);
} else { } else {
@ -335,17 +335,16 @@ ttcompatsetflags(tp, t)
else else
lflag &= ~ECHO; lflag &= ~ECHO;
cflag &= ~(CSIZE|PARENB);
if (flags&(RAW|LITOUT|PASS8)) { if (flags&(RAW|LITOUT|PASS8)) {
cflag &= ~(CSIZE|PARENB);
cflag |= CS8; cflag |= CS8;
if (!(flags&(RAW|PASS8)) || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP)) if ((flags&(RAW|PASS8)) == 0)
iflag |= ISTRIP; iflag |= ISTRIP;
else else
iflag &= ~ISTRIP; iflag &= ~ISTRIP;
} else { } else {
cflag |= CS7; cflag &= ~CSIZE;
if ((flags&(EVENP|ODDP))) cflag |= CS7|PARENB;
cflag |= PARENB;
iflag |= ISTRIP; iflag |= ISTRIP;
} }
if ((flags&(EVENP|ODDP)) == EVENP) { if ((flags&(EVENP|ODDP)) == EVENP) {
@ -399,24 +398,28 @@ ttcompatsetlflags(tp, t)
lflag |= IXANY; lflag |= IXANY;
else else
lflag &= ~IXANY; lflag &= ~IXANY;
lflag &= ~(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH); if (flags & MDMBUF)
lflag |= flags&(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH); cflag |= MDMBUF;
cflag &= ~(CSIZE|PARENB); else
cflag &= ~MDMBUF;
if (flags&NOHANG)
cflag &= ~HUPCL;
else
cflag |= HUPCL;
lflag &= ~(TOSTOP|FLUSHO|PENDIN|NOFLSH);
lflag |= flags&(TOSTOP|FLUSHO|PENDIN|NOFLSH);
if (flags&(LITOUT|PASS8)) { if (flags&(LITOUT|PASS8)) {
iflag &= ~ISTRIP;
cflag &= ~(CSIZE|PARENB);
cflag |= CS8; cflag |= CS8;
if (flags&(LITOUT|RAW)) if (flags&LITOUT)
oflag &= ~OPOST; oflag &= ~OPOST;
else if ((flags&(PASS8|RAW)) == 0)
oflag |= OPOST;
if (!(flags&(RAW|PASS8)) || (flags&(RAW|PASS8|ANYP)) == (PASS8|ANYP))
iflag |= ISTRIP; iflag |= ISTRIP;
else
iflag &= ~ISTRIP;
} else if ((flags&RAW) == 0) { } else if ((flags&RAW) == 0) {
cflag |= CS7; cflag &= ~CSIZE;
if ((flags&(EVENP|ODDP))) cflag |= CS7|PARENB;
cflag |= PARENB; oflag |= OPOST;
oflag |= ISTRIP|OPOST;
} }
t->c_iflag = iflag; t->c_iflag = iflag;
t->c_oflag = oflag; t->c_oflag = oflag;