BSD 4_3_Net_2 release
[unix-history] / usr / src / sys / kern / tty_compat.c
index 50625d3..9bfd6cd 100644 (file)
@@ -1,22 +1,45 @@
-/*
- * Copyright (c) 1982, 1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1982, 1986, 1991 The Regents of the University of California.
+ * All rights reserved.
  *
  *
- *     @(#)ttcompat.c  7.11 (Berkeley) 4/8/88
+ * 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. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. 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.
+ *
+ *     @(#)tty_compat.c        7.10 (Berkeley) 5/9/91
  */
 
 /* 
  */
 
 /* 
- * mapping routines for old line disciplines (yuck)
+ * mapping routines for old line discipline (yuck)
  */
 #ifdef COMPAT_43
 
  */
 #ifdef COMPAT_43
 
-#include "../machine/reg.h"
-
 #include "param.h"
 #include "systm.h"
 #include "param.h"
 #include "systm.h"
-#include "dir.h"
-#include "user.h"
 #include "ioctl.h"
 #include "tty.h"
 #include "termios.h"
 #include "ioctl.h"
 #include "tty.h"
 #include "termios.h"
 #include "file.h"
 #include "conf.h"
 #include "dkstat.h"
 #include "file.h"
 #include "conf.h"
 #include "dkstat.h"
-#include "uio.h"
 #include "kernel.h"
 #include "syslog.h"
 
 #include "kernel.h"
 #include "syslog.h"
 
-/* begin XXX */
-#undef t_erase
-#undef t_kill
-#undef t_intrc
-#undef t_quitc
-#undef t_startc
-#undef t_stopc
-#undef t_eofc
-#undef t_brkc
-#undef t_suspc
-#undef t_dsuspc
-#undef t_rprntc
-#undef t_flushc
-#undef t_werasc
-#undef t_lnextc
-/* end XXX */
+int ttydebug = 0;
 
 
-/* should fold these two tables into one */
 static struct speedtab compatspeeds[] = {
        38400,  15,
        19200,  14,
 static struct speedtab compatspeeds[] = {
        38400,  15,
        19200,  14,
@@ -75,7 +81,8 @@ ttcompat(tp, com, data, flag)
        register struct tty *tp;
        caddr_t data;
 {
        register struct tty *tp;
        caddr_t data;
 {
-       switch(com) {
+
+       switch (com) {
        case TIOCGETP: {
                register struct sgttyb *sg = (struct sgttyb *)data;
                register u_char *cc = tp->t_cc;
        case TIOCGETP: {
                register struct sgttyb *sg = (struct sgttyb *)data;
                register u_char *cc = tp->t_cc;
@@ -89,10 +96,9 @@ ttcompat(tp, com, data, flag)
                        speed = ttspeedtab(tp->t_ispeed, compatspeeds);
                        sg->sg_ispeed = (speed == -1) ? 15 : speed;
                }
                        speed = ttspeedtab(tp->t_ispeed, compatspeeds);
                        sg->sg_ispeed = (speed == -1) ? 15 : speed;
                }
-
                sg->sg_erase = cc[VERASE];
                sg->sg_kill = cc[VKILL];
                sg->sg_erase = cc[VERASE];
                sg->sg_kill = cc[VKILL];
-               sg->sg_flags = ttcompatgetflags(tp) & 0xffff;
+               sg->sg_flags = ttcompatgetflags(tp);
                break;
        }
 
                break;
        }
 
@@ -103,7 +109,6 @@ ttcompat(tp, com, data, flag)
                int speed;
 
                term = tp->t_termios;
                int speed;
 
                term = tp->t_termios;
-
                if ((speed = sg->sg_ispeed) > 15 || speed < 0)
                        term.c_ispeed = speed;
                else
                if ((speed = sg->sg_ispeed) > 15 || speed < 0)
                        term.c_ispeed = speed;
                else
@@ -112,14 +117,9 @@ ttcompat(tp, com, data, flag)
                        term.c_ospeed = speed;
                else
                        term.c_ospeed = compatspcodes[speed];
                        term.c_ospeed = speed;
                else
                        term.c_ospeed = compatspcodes[speed];
-               
                term.c_cc[VERASE] = sg->sg_erase;
                term.c_cc[VKILL] = sg->sg_kill;
                term.c_cc[VERASE] = sg->sg_erase;
                term.c_cc[VKILL] = sg->sg_kill;
-               if (sg->sg_erase == -1)
-                       term.c_cc[VERASE2] = POSIX_V_DISABLE;
-
-               tp->t_flags = (tp->t_flags&0xffff0000) | sg->sg_flags;
-
+               tp->t_flags = tp->t_flags&0xffff0000 | sg->sg_flags&0xffff;
                ttcompatsetflags(tp, &term);
                return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA, 
                        &term, flag));
                ttcompatsetflags(tp, &term);
                return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA, 
                        &term, flag));
@@ -148,7 +148,7 @@ ttcompat(tp, com, data, flag)
                cc[VEOF] = tc->t_eofc;
                cc[VEOL] = tc->t_brkc;
                if (tc->t_brkc == -1)
                cc[VEOF] = tc->t_eofc;
                cc[VEOL] = tc->t_brkc;
                if (tc->t_brkc == -1)
-                       cc[VEOL2] = POSIX_V_DISABLE;
+                       cc[VEOL2] = _POSIX_VDISABLE;
                break;
        }
        case TIOCSLTC: {
                break;
        }
        case TIOCSLTC: {
@@ -158,7 +158,7 @@ ttcompat(tp, com, data, flag)
                cc[VSUSP] = ltc->t_suspc;
                cc[VDSUSP] = ltc->t_dsuspc;
                cc[VREPRINT] = ltc->t_rprntc;
                cc[VSUSP] = ltc->t_suspc;
                cc[VDSUSP] = ltc->t_dsuspc;
                cc[VREPRINT] = ltc->t_rprntc;
-               cc[VFLUSHO] = ltc->t_flushc;
+               cc[VDISCARD] = ltc->t_flushc;
                cc[VWERASE] = ltc->t_werasc;
                cc[VLNEXT] = ltc->t_lnextc;
                break;
                cc[VWERASE] = ltc->t_werasc;
                cc[VLNEXT] = ltc->t_lnextc;
                break;
@@ -170,7 +170,7 @@ ttcompat(tp, com, data, flag)
                ltc->t_suspc = cc[VSUSP];
                ltc->t_dsuspc = cc[VDSUSP];
                ltc->t_rprntc = cc[VREPRINT];
                ltc->t_suspc = cc[VSUSP];
                ltc->t_dsuspc = cc[VDSUSP];
                ltc->t_rprntc = cc[VREPRINT];
-               ltc->t_flushc = cc[VFLUSHO];
+               ltc->t_flushc = cc[VDISCARD];
                ltc->t_werasc = cc[VWERASE];
                ltc->t_lnextc = cc[VLNEXT];
                break;
                ltc->t_werasc = cc[VWERASE];
                ltc->t_lnextc = cc[VLNEXT];
                break;
@@ -182,29 +182,45 @@ ttcompat(tp, com, data, flag)
 
                term = tp->t_termios;
                if (com == TIOCLSET)
 
                term = tp->t_termios;
                if (com == TIOCLSET)
-                       tp->t_flags = (tp->t_flags&0xffff) | *(short *)data<<16;
+                       tp->t_flags = (tp->t_flags&0xffff) | *(int *)data<<16;
                else {
                        tp->t_flags = 
                         (ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
                        if (com == TIOCLBIS)
                else {
                        tp->t_flags = 
                         (ttcompatgetflags(tp)&0xffff0000)|(tp->t_flags&0xffff);
                        if (com == TIOCLBIS)
-                               tp->t_flags |= *(short *)data<<16;
+                               tp->t_flags |= *(int *)data<<16;
                        else
                        else
-                               tp->t_flags &= ~(*(short *)data<<16);
+                               tp->t_flags &= ~(*(int *)data<<16);
                }
                ttcompatsetlflags(tp, &term);
                return (ttioctl(tp, TIOCSETA, &term, flag));
        }
        case TIOCLGET:
                }
                ttcompatsetlflags(tp, &term);
                return (ttioctl(tp, TIOCSETA, &term, flag));
        }
        case TIOCLGET:
-               *(short *)data = ttcompatgetflags(tp)>>16;
+               *(int *)data = ttcompatgetflags(tp)>>16;
+               if (ttydebug)
+                       printf("CLGET: returning %x\n", *(int *)data);
                break;
                break;
+
+       case OTIOCGETD:
+               *(int *)data = tp->t_line ? tp->t_line : 2;
+               break;
+
+       case OTIOCSETD: {
+               int ldisczero = 0;
+
+               return (ttioctl(tp, TIOCSETD, 
+                       *(int *)data == 2 ? (caddr_t)&ldisczero : data, flag));
+           }
+
+       case OTIOCCONS:
+               *(int *)data = 1;
+               return (ttioctl(tp, TIOCCONS, data, flag));
+
        default:
                return (-1);
        }
        default:
                return (-1);
        }
-       return(0);
+       return (0);
 }
 
 }
 
-
-
 ttcompatgetflags(tp)
        register struct tty *tp;
 {
 ttcompatgetflags(tp)
        register struct tty *tp;
 {
@@ -242,11 +258,10 @@ ttcompatgetflags(tp)
        }
        if (oflag&OXTABS)
                flags |= XTABS;
        }
        if (oflag&OXTABS)
                flags |= XTABS;
-
        if (lflag&ECHOE)
        if (lflag&ECHOE)
-               flags |= CRTERA;
+               flags |= CRTERA|CRTBS;
        if (lflag&ECHOKE)
        if (lflag&ECHOKE)
-               flags |= CRTKIL;
+               flags |= CRTKIL|CRTBS;
        if (lflag&ECHOPRT)
                flags |= PRTERA;
        if (lflag&ECHOCTL)
        if (lflag&ECHOPRT)
                flags |= PRTERA;
        if (lflag&ECHOCTL)
@@ -254,7 +269,8 @@ ttcompatgetflags(tp)
        if ((iflag&IXANY) == 0)
                flags |= DECCTQ;
        flags |= lflag&(ECHO|MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
        if ((iflag&IXANY) == 0)
                flags |= DECCTQ;
        flags |= lflag&(ECHO|MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
-
+if (ttydebug)
+       printf("getflags: %x\n", flags);
        return (flags);
 }
 
        return (flags);
 }
 
@@ -271,11 +287,11 @@ ttcompatsetflags(tp, t)
        if (flags & RAW) {
                iflag &= IXOFF;
                oflag &= ~OPOST;
        if (flags & RAW) {
                iflag &= IXOFF;
                oflag &= ~OPOST;
-               lflag &= ~(ECHOCTL|ISIG|ICANON);
+               lflag &= ~(ECHOCTL|ISIG|ICANON|IEXTEN);
        } else {
        } else {
-               iflag |= BRKINT|IXON|IEXTEN|IMAXBEL;
+               iflag |= BRKINT|IXON|IMAXBEL;
                oflag |= OPOST;
                oflag |= OPOST;
-               lflag |= ISIG;
+               lflag |= ISIG|IEXTEN|ECHOCTL;   /* XXX was echoctl on ? */
                if (flags & XTABS)
                        oflag |= OXTABS;
                else
                if (flags & XTABS)
                        oflag |= OXTABS;
                else
@@ -302,9 +318,12 @@ ttcompatsetflags(tp, t)
                cflag |= CS8;
                if ((flags&(RAW|PASS8)) == 0)
                        iflag |= ISTRIP;
                cflag |= CS8;
                if ((flags&(RAW|PASS8)) == 0)
                        iflag |= ISTRIP;
+               else
+                       iflag &= ~ISTRIP;
        } else {
                cflag &= ~CSIZE;
                cflag |= CS7|PARENB;
        } else {
                cflag &= ~CSIZE;
                cflag |= CS7|PARENB;
+               iflag |= ISTRIP;
        }
        if ((flags&(EVENP|ODDP)) == EVENP) {
                iflag |= INPCK;
        }
        if ((flags&(EVENP|ODDP)) == EVENP) {
                iflag |= INPCK;
@@ -326,7 +345,6 @@ ttcompatsetflags(tp, t)
        t->c_cflag = cflag;
 }
 
        t->c_cflag = cflag;
 }
 
-/* XXX - rethink this whole routine */
 ttcompatsetlflags(tp, t)
        register struct tty *tp;
        register struct termios *t;
 ttcompatsetlflags(tp, t)
        register struct tty *tp;
        register struct termios *t;
@@ -336,10 +354,11 @@ ttcompatsetlflags(tp, t)
        register long oflag = t->c_oflag;
        register long lflag = t->c_lflag;
        register long cflag = t->c_cflag;
        register long oflag = t->c_oflag;
        register long lflag = t->c_lflag;
        register long cflag = t->c_cflag;
+
        if (flags&CRTERA)
                lflag |= ECHOE;
        else
        if (flags&CRTERA)
                lflag |= ECHOE;
        else
-               lflag &= ECHOE;
+               lflag &= ~ECHOE;
        if (flags&CRTKIL)
                lflag |= ECHOKE;
        else
        if (flags&CRTKIL)
                lflag |= ECHOKE;
        else
@@ -356,10 +375,8 @@ ttcompatsetlflags(tp, t)
                lflag |= IXANY;
        else
                lflag &= ~IXANY;
                lflag |= IXANY;
        else
                lflag &= ~IXANY;
-
        lflag &= ~(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
        lflag |= flags&(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
        lflag &= ~(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
        lflag |= flags&(MDMBUF|TOSTOP|FLUSHO|NOHANG|PENDIN|NOFLSH);
-
        if (flags&(LITOUT|PASS8)) {
                iflag &= ~ISTRIP;
                cflag &= ~(CSIZE|PARENB);
        if (flags&(LITOUT|PASS8)) {
                iflag &= ~ISTRIP;
                cflag &= ~(CSIZE|PARENB);