Home | History | Annotate | Line # | Download | only in common
tty_43.c revision 1.14
      1  1.14    atatat /*	$NetBSD: tty_43.c,v 1.14 2002/03/17 19:40:53 atatat Exp $	*/
      2   1.1  christos 
      3   1.1  christos /*-
      4   1.1  christos  * Copyright (c) 1982, 1986, 1991, 1993
      5   1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6   1.1  christos  *
      7   1.1  christos  * Redistribution and use in source and binary forms, with or without
      8   1.1  christos  * modification, are permitted provided that the following conditions
      9   1.1  christos  * are met:
     10   1.1  christos  * 1. Redistributions of source code must retain the above copyright
     11   1.1  christos  *    notice, this list of conditions and the following disclaimer.
     12   1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     13   1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     14   1.1  christos  *    documentation and/or other materials provided with the distribution.
     15   1.1  christos  * 3. All advertising materials mentioning features or use of this software
     16   1.1  christos  *    must display the following acknowledgement:
     17   1.1  christos  *	This product includes software developed by the University of
     18   1.1  christos  *	California, Berkeley and its contributors.
     19   1.1  christos  * 4. Neither the name of the University nor the names of its contributors
     20   1.1  christos  *    may be used to endorse or promote products derived from this software
     21   1.1  christos  *    without specific prior written permission.
     22   1.1  christos  *
     23   1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24   1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25   1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26   1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27   1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28   1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29   1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30   1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31   1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32   1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33   1.1  christos  * SUCH DAMAGE.
     34   1.1  christos  *
     35   1.8      fvdl  *	@(#)tty_compat.c	8.2 (Berkeley) 1/9/95
     36   1.1  christos  */
     37   1.1  christos 
     38   1.1  christos /*
     39   1.1  christos  * mapping routines for old line discipline (yuck)
     40   1.1  christos  */
     41  1.13     lukem 
     42  1.13     lukem #include <sys/cdefs.h>
     43  1.14    atatat __KERNEL_RCSID(0, "$NetBSD: tty_43.c,v 1.14 2002/03/17 19:40:53 atatat Exp $");
     44  1.13     lukem 
     45   1.1  christos #include <sys/param.h>
     46   1.1  christos #include <sys/systm.h>
     47   1.1  christos #include <sys/ioctl.h>
     48   1.1  christos #include <sys/proc.h>
     49  1.11     itohy #include <sys/conf.h>
     50   1.1  christos #include <sys/tty.h>
     51   1.1  christos #include <sys/termios.h>
     52   1.1  christos #include <sys/file.h>
     53   1.1  christos #include <sys/kernel.h>
     54   1.1  christos #include <sys/syslog.h>
     55   1.2  christos #include <sys/ioctl_compat.h>
     56   1.1  christos 
     57   1.4     veego /*
     58   1.4     veego  * XXX libcompat files should be included with config attributes
     59   1.4     veego  */
     60   1.4     veego #ifdef COMPAT_OLDTTY
     61   1.4     veego 
     62   1.1  christos int ttydebug = 0;
     63   1.1  christos 
     64   1.1  christos static struct speedtab compatspeeds[] = {
     65   1.1  christos #define MAX_SPEED	17
     66   1.1  christos 	{ 115200, 17 },
     67   1.1  christos 	{ 57600, 16 },
     68   1.1  christos 	{ 38400, 15 },
     69   1.1  christos 	{ 19200, 14 },
     70   1.1  christos 	{ 9600,	13 },
     71   1.1  christos 	{ 4800,	12 },
     72   1.1  christos 	{ 2400,	11 },
     73   1.1  christos 	{ 1800,	10 },
     74   1.1  christos 	{ 1200,	9 },
     75   1.1  christos 	{ 600,	8 },
     76   1.1  christos 	{ 300,	7 },
     77   1.1  christos 	{ 200,	6 },
     78   1.1  christos 	{ 150,	5 },
     79   1.1  christos 	{ 134,	4 },
     80   1.1  christos 	{ 110,	3 },
     81   1.1  christos 	{ 75,	2 },
     82   1.1  christos 	{ 50,	1 },
     83   1.1  christos 	{ 0,	0 },
     84   1.1  christos 	{ -1,	-1 },
     85   1.1  christos };
     86   1.1  christos static int compatspcodes[] = {
     87   1.1  christos 	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
     88   1.1  christos 	1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200
     89   1.1  christos };
     90   1.1  christos 
     91   1.1  christos /* Macros to clear/set/test flags. */
     92   1.1  christos #define	SET(t, f)	(t) |= (f)
     93   1.1  christos #define	CLR(t, f)	(t) &= ~(f)
     94   1.1  christos #define	ISSET(t, f)	((t) & (f))
     95   1.1  christos 
     96   1.3  christos int ttcompatgetflags __P((struct tty *));
     97   1.3  christos void ttcompatsetflags __P((struct tty *, struct termios *));
     98   1.3  christos void ttcompatsetlflags __P((struct tty *, struct termios *));
     99   1.3  christos 
    100   1.1  christos /*ARGSUSED*/
    101   1.3  christos int
    102   1.1  christos ttcompat(tp, com, data, flag, p)
    103  1.10  augustss 	struct tty *tp;
    104   1.1  christos 	u_long com;
    105   1.1  christos 	caddr_t data;
    106   1.1  christos 	int flag;
    107   1.1  christos 	struct proc *p;
    108   1.1  christos {
    109   1.1  christos 
    110   1.1  christos 	switch (com) {
    111   1.1  christos 	case TIOCGETP: {
    112  1.10  augustss 		struct sgttyb *sg = (struct sgttyb *)data;
    113  1.10  augustss 		u_char *cc = tp->t_cc;
    114  1.10  augustss 		int speed;
    115   1.1  christos 
    116   1.1  christos 		speed = ttspeedtab(tp->t_ospeed, compatspeeds);
    117   1.1  christos 		sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed;
    118   1.1  christos 		if (tp->t_ispeed == 0)
    119   1.1  christos 			sg->sg_ispeed = sg->sg_ospeed;
    120   1.1  christos 		else {
    121   1.1  christos 			speed = ttspeedtab(tp->t_ispeed, compatspeeds);
    122   1.1  christos 			sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed;
    123   1.1  christos 		}
    124   1.1  christos 		sg->sg_erase = cc[VERASE];
    125   1.1  christos 		sg->sg_kill = cc[VKILL];
    126   1.1  christos 		sg->sg_flags = ttcompatgetflags(tp);
    127   1.1  christos 		break;
    128   1.1  christos 	}
    129   1.1  christos 
    130   1.1  christos 	case TIOCSETP:
    131   1.1  christos 	case TIOCSETN: {
    132  1.10  augustss 		struct sgttyb *sg = (struct sgttyb *)data;
    133   1.1  christos 		struct termios term;
    134   1.1  christos 		int speed;
    135   1.1  christos 
    136   1.1  christos 		term = tp->t_termios;
    137   1.1  christos 		if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
    138   1.1  christos 			term.c_ispeed = speed;
    139   1.1  christos 		else
    140   1.1  christos 			term.c_ispeed = compatspcodes[speed];
    141   1.1  christos 		if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
    142   1.1  christos 			term.c_ospeed = speed;
    143   1.1  christos 		else
    144   1.1  christos 			term.c_ospeed = compatspcodes[speed];
    145   1.1  christos 		term.c_cc[VERASE] = sg->sg_erase;
    146   1.1  christos 		term.c_cc[VKILL] = sg->sg_kill;
    147   1.1  christos 		tp->t_flags = (ttcompatgetflags(tp)&0xffff0000) | (sg->sg_flags&0xffff);
    148   1.1  christos 		ttcompatsetflags(tp, &term);
    149   1.1  christos 		return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA,
    150   1.1  christos 			(caddr_t)&term, flag, p));
    151   1.1  christos 	}
    152   1.1  christos 
    153   1.1  christos 	case TIOCGETC: {
    154   1.1  christos 		struct tchars *tc = (struct tchars *)data;
    155  1.10  augustss 		u_char *cc = tp->t_cc;
    156   1.1  christos 
    157   1.1  christos 		tc->t_intrc = cc[VINTR];
    158   1.1  christos 		tc->t_quitc = cc[VQUIT];
    159   1.1  christos 		tc->t_startc = cc[VSTART];
    160   1.1  christos 		tc->t_stopc = cc[VSTOP];
    161   1.1  christos 		tc->t_eofc = cc[VEOF];
    162   1.1  christos 		tc->t_brkc = cc[VEOL];
    163   1.1  christos 		break;
    164   1.1  christos 	}
    165   1.1  christos 	case TIOCSETC: {
    166   1.1  christos 		struct tchars *tc = (struct tchars *)data;
    167  1.10  augustss 		u_char *cc = tp->t_cc;
    168   1.1  christos 
    169   1.1  christos 		cc[VINTR] = tc->t_intrc;
    170   1.1  christos 		cc[VQUIT] = tc->t_quitc;
    171   1.1  christos 		cc[VSTART] = tc->t_startc;
    172   1.1  christos 		cc[VSTOP] = tc->t_stopc;
    173   1.1  christos 		cc[VEOF] = tc->t_eofc;
    174   1.1  christos 		cc[VEOL] = tc->t_brkc;
    175   1.5      mark 		if (tc->t_brkc == (char)-1)
    176   1.1  christos 			cc[VEOL2] = _POSIX_VDISABLE;
    177   1.1  christos 		break;
    178   1.1  christos 	}
    179   1.1  christos 	case TIOCSLTC: {
    180   1.1  christos 		struct ltchars *ltc = (struct ltchars *)data;
    181  1.10  augustss 		u_char *cc = tp->t_cc;
    182   1.1  christos 
    183   1.1  christos 		cc[VSUSP] = ltc->t_suspc;
    184   1.1  christos 		cc[VDSUSP] = ltc->t_dsuspc;
    185   1.1  christos 		cc[VREPRINT] = ltc->t_rprntc;
    186   1.1  christos 		cc[VDISCARD] = ltc->t_flushc;
    187   1.1  christos 		cc[VWERASE] = ltc->t_werasc;
    188   1.1  christos 		cc[VLNEXT] = ltc->t_lnextc;
    189   1.1  christos 		break;
    190   1.1  christos 	}
    191   1.1  christos 	case TIOCGLTC: {
    192   1.1  christos 		struct ltchars *ltc = (struct ltchars *)data;
    193  1.10  augustss 		u_char *cc = tp->t_cc;
    194   1.1  christos 
    195   1.1  christos 		ltc->t_suspc = cc[VSUSP];
    196   1.1  christos 		ltc->t_dsuspc = cc[VDSUSP];
    197   1.1  christos 		ltc->t_rprntc = cc[VREPRINT];
    198   1.1  christos 		ltc->t_flushc = cc[VDISCARD];
    199   1.1  christos 		ltc->t_werasc = cc[VWERASE];
    200   1.1  christos 		ltc->t_lnextc = cc[VLNEXT];
    201   1.1  christos 		break;
    202   1.1  christos 	}
    203   1.1  christos 	case TIOCLBIS:
    204   1.1  christos 	case TIOCLBIC:
    205   1.1  christos 	case TIOCLSET: {
    206   1.1  christos 		struct termios term;
    207   1.1  christos 		int flags;
    208   1.1  christos 
    209   1.1  christos 		term = tp->t_termios;
    210   1.1  christos 		flags = ttcompatgetflags(tp);
    211   1.1  christos 		switch (com) {
    212   1.1  christos 		case TIOCLSET:
    213   1.1  christos 			tp->t_flags = (flags&0xffff) | (*(int *)data<<16);
    214   1.1  christos 			break;
    215   1.1  christos 		case TIOCLBIS:
    216   1.1  christos 			tp->t_flags = flags | (*(int *)data<<16);
    217   1.1  christos 			break;
    218   1.1  christos 		case TIOCLBIC:
    219   1.1  christos 			tp->t_flags = flags & ~(*(int *)data<<16);
    220   1.1  christos 			break;
    221   1.1  christos 		}
    222   1.1  christos 		ttcompatsetlflags(tp, &term);
    223   1.1  christos 		return (ttioctl(tp, TIOCSETA, (caddr_t)&term, flag, p));
    224   1.1  christos 	}
    225   1.1  christos 	case TIOCLGET:
    226   1.1  christos 		*(int *)data = ttcompatgetflags(tp)>>16;
    227   1.1  christos 		if (ttydebug)
    228   1.7  christos 			printf("CLGET: returning %x\n", *(int *)data);
    229   1.1  christos 		break;
    230   1.1  christos 
    231   1.1  christos 	case OTIOCGETD:
    232  1.12       eeh 		*(int *)data = (tp->t_linesw != NULL) ? tp->t_linesw->l_no : 2;
    233   1.1  christos 		break;
    234   1.1  christos 
    235   1.1  christos 	case OTIOCSETD: {
    236   1.1  christos 		int ldisczero = 0;
    237   1.1  christos 
    238   1.1  christos 		return (ttioctl(tp, TIOCSETD,
    239   1.1  christos 			*(int *)data == 2 ? (caddr_t)&ldisczero : data, flag,
    240   1.1  christos 			p));
    241   1.1  christos 	    }
    242   1.1  christos 
    243   1.1  christos 	case OTIOCCONS:
    244   1.1  christos 		*(int *)data = 1;
    245   1.1  christos 		return (ttioctl(tp, TIOCCONS, data, flag, p));
    246   1.1  christos 
    247   1.1  christos 	case TIOCHPCL:
    248   1.1  christos 		SET(tp->t_cflag, HUPCL);
    249   1.1  christos 		break;
    250   1.1  christos 
    251   1.1  christos 	case TIOCGSID:
    252   1.1  christos 		if (tp->t_session == NULL)
    253   1.1  christos 			return ENOTTY;
    254   1.1  christos 
    255   1.1  christos 		if (tp->t_session->s_leader == NULL)
    256   1.1  christos 			return ENOTTY;
    257   1.1  christos 
    258   1.1  christos 		*(int *) data =  tp->t_session->s_leader->p_pid;
    259   1.1  christos 		break;
    260   1.1  christos 
    261   1.1  christos 	default:
    262  1.14    atatat 		return (EPASSTHROUGH);
    263   1.1  christos 	}
    264   1.1  christos 	return (0);
    265   1.1  christos }
    266   1.1  christos 
    267   1.1  christos int
    268   1.1  christos ttcompatgetflags(tp)
    269  1.10  augustss 	struct tty *tp;
    270   1.1  christos {
    271  1.10  augustss 	tcflag_t iflag = tp->t_iflag;
    272  1.10  augustss 	tcflag_t lflag = tp->t_lflag;
    273  1.10  augustss 	tcflag_t oflag = tp->t_oflag;
    274  1.10  augustss 	tcflag_t cflag = tp->t_cflag;
    275  1.10  augustss 	int flags = 0;
    276   1.1  christos 
    277   1.1  christos 	if (ISSET(iflag, IXOFF))
    278   1.1  christos 		SET(flags, TANDEM);
    279   1.1  christos 	if (ISSET(iflag, ICRNL) || ISSET(oflag, ONLCR))
    280   1.1  christos 		SET(flags, CRMOD);
    281   1.1  christos 	if (ISSET(cflag, PARENB)) {
    282   1.1  christos 		if (ISSET(iflag, INPCK)) {
    283   1.1  christos 			if (ISSET(cflag, PARODD))
    284   1.1  christos 				SET(flags, ODDP);
    285   1.1  christos 			else
    286   1.1  christos 				SET(flags, EVENP);
    287   1.1  christos 		} else
    288   1.1  christos 			SET(flags, ANYP);
    289   1.1  christos 	}
    290   1.1  christos 
    291   1.1  christos 	if (!ISSET(lflag, ICANON)) {
    292   1.1  christos 		/* fudge */
    293   1.1  christos 		if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) ||
    294   1.1  christos 		    ISSET(cflag, PARENB))
    295   1.1  christos 			SET(flags, CBREAK);
    296   1.1  christos 		else
    297   1.1  christos 			SET(flags, RAW);
    298   1.1  christos 	}
    299   1.1  christos 
    300   1.1  christos 	if (ISSET(flags, RAW))
    301   1.1  christos 		SET(flags, ISSET(tp->t_flags, LITOUT|PASS8));
    302   1.1  christos 	else if (ISSET(cflag, CSIZE) == CS8) {
    303   1.1  christos 		if (!ISSET(oflag, OPOST))
    304   1.1  christos 			SET(flags, LITOUT);
    305   1.1  christos 		if (!ISSET(iflag, ISTRIP))
    306   1.1  christos 			SET(flags, PASS8);
    307   1.1  christos 	}
    308   1.1  christos 
    309   1.1  christos 	if (ISSET(cflag, MDMBUF))
    310   1.1  christos 		SET(flags, MDMBUF);
    311   1.1  christos 	if (!ISSET(cflag, HUPCL))
    312   1.1  christos 		SET(flags, NOHANG);
    313   1.1  christos 	if (ISSET(oflag, OXTABS))
    314   1.1  christos 		SET(flags, XTABS);
    315   1.1  christos 	if (ISSET(lflag, ECHOE))
    316   1.1  christos 		SET(flags, CRTERA|CRTBS);
    317   1.1  christos 	if (ISSET(lflag, ECHOKE))
    318   1.1  christos 		SET(flags, CRTKIL|CRTBS);
    319   1.1  christos 	if (ISSET(lflag, ECHOPRT))
    320   1.1  christos 		SET(flags, PRTERA);
    321   1.1  christos 	if (ISSET(lflag, ECHOCTL))
    322   1.1  christos 		SET(flags, CTLECH);
    323   1.1  christos 	if (!ISSET(iflag, IXANY))
    324   1.1  christos 		SET(flags, DECCTQ);
    325   1.1  christos 	SET(flags, ISSET(lflag, ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH));
    326   1.1  christos 	if (ttydebug)
    327   1.7  christos 		printf("getflags: %x\n", flags);
    328   1.1  christos 	return (flags);
    329   1.1  christos }
    330   1.1  christos 
    331   1.3  christos void
    332   1.1  christos ttcompatsetflags(tp, t)
    333  1.10  augustss 	struct tty *tp;
    334  1.10  augustss 	struct termios *t;
    335   1.1  christos {
    336  1.10  augustss 	int flags = tp->t_flags;
    337  1.10  augustss 	tcflag_t iflag = t->c_iflag;
    338  1.10  augustss 	tcflag_t oflag = t->c_oflag;
    339  1.10  augustss 	tcflag_t lflag = t->c_lflag;
    340  1.10  augustss 	tcflag_t cflag = t->c_cflag;
    341   1.1  christos 
    342   1.1  christos 	if (ISSET(flags, TANDEM))
    343   1.1  christos 		SET(iflag, IXOFF);
    344   1.1  christos 	else
    345   1.1  christos 		CLR(iflag, IXOFF);
    346   1.1  christos 	if (ISSET(flags, ECHO))
    347   1.1  christos 		SET(lflag, ECHO);
    348   1.1  christos 	else
    349   1.1  christos 		CLR(lflag, ECHO);
    350   1.1  christos 	if (ISSET(flags, CRMOD)) {
    351   1.1  christos 		SET(iflag, ICRNL);
    352   1.1  christos 		SET(oflag, ONLCR);
    353   1.1  christos 	} else {
    354   1.1  christos 		CLR(iflag, ICRNL);
    355   1.1  christos 		CLR(oflag, ONLCR);
    356   1.1  christos 	}
    357   1.1  christos 	if (ISSET(flags, XTABS))
    358   1.1  christos 		SET(oflag, OXTABS);
    359   1.1  christos 	else
    360   1.1  christos 		CLR(oflag, OXTABS);
    361   1.1  christos 
    362   1.1  christos 
    363   1.1  christos 	if (ISSET(flags, RAW)) {
    364   1.1  christos 		iflag &= IXOFF;
    365   1.1  christos 		CLR(lflag, ISIG|ICANON|IEXTEN);
    366   1.1  christos 		CLR(cflag, PARENB);
    367   1.1  christos 	} else {
    368   1.1  christos 		SET(iflag, BRKINT|IXON|IMAXBEL);
    369   1.1  christos 		SET(lflag, ISIG|IEXTEN);
    370   1.1  christos 		if (ISSET(flags, CBREAK))
    371   1.1  christos 			CLR(lflag, ICANON);
    372   1.1  christos 		else
    373   1.1  christos 			SET(lflag, ICANON);
    374   1.1  christos 		switch (ISSET(flags, ANYP)) {
    375   1.1  christos 		case 0:
    376   1.1  christos 			CLR(cflag, PARENB);
    377   1.1  christos 			break;
    378   1.1  christos 		case ANYP:
    379   1.1  christos 			SET(cflag, PARENB);
    380   1.1  christos 			CLR(iflag, INPCK);
    381   1.1  christos 			break;
    382   1.1  christos 		case EVENP:
    383   1.1  christos 			SET(cflag, PARENB);
    384   1.1  christos 			SET(iflag, INPCK);
    385   1.1  christos 			CLR(cflag, PARODD);
    386   1.1  christos 			break;
    387   1.1  christos 		case ODDP:
    388   1.1  christos 			SET(cflag, PARENB);
    389   1.1  christos 			SET(iflag, INPCK);
    390   1.1  christos 			SET(cflag, PARODD);
    391   1.1  christos 			break;
    392   1.1  christos 		}
    393   1.1  christos 	}
    394   1.1  christos 
    395   1.1  christos 	if (ISSET(flags, RAW|LITOUT|PASS8)) {
    396   1.1  christos 		CLR(cflag, CSIZE);
    397   1.1  christos 		SET(cflag, CS8);
    398   1.1  christos 		if (!ISSET(flags, RAW|PASS8))
    399   1.1  christos 			SET(iflag, ISTRIP);
    400   1.1  christos 		else
    401   1.1  christos 			CLR(iflag, ISTRIP);
    402   1.1  christos 		if (!ISSET(flags, RAW|LITOUT))
    403   1.1  christos 			SET(oflag, OPOST);
    404   1.1  christos 		else
    405   1.1  christos 			CLR(oflag, OPOST);
    406   1.1  christos 	} else {
    407   1.1  christos 		CLR(cflag, CSIZE);
    408   1.1  christos 		SET(cflag, CS7);
    409   1.1  christos 		SET(iflag, ISTRIP);
    410   1.1  christos 		SET(oflag, OPOST);
    411   1.1  christos 	}
    412   1.1  christos 
    413   1.1  christos 	t->c_iflag = iflag;
    414   1.1  christos 	t->c_oflag = oflag;
    415   1.1  christos 	t->c_lflag = lflag;
    416   1.1  christos 	t->c_cflag = cflag;
    417   1.1  christos }
    418   1.1  christos 
    419   1.3  christos void
    420   1.1  christos ttcompatsetlflags(tp, t)
    421  1.10  augustss 	struct tty *tp;
    422  1.10  augustss 	struct termios *t;
    423   1.1  christos {
    424  1.10  augustss 	int flags = tp->t_flags;
    425  1.10  augustss 	tcflag_t iflag = t->c_iflag;
    426  1.10  augustss 	tcflag_t oflag = t->c_oflag;
    427  1.10  augustss 	tcflag_t lflag = t->c_lflag;
    428  1.10  augustss 	tcflag_t cflag = t->c_cflag;
    429   1.1  christos 
    430   1.1  christos 	/* Nothing we can do with CRTBS. */
    431   1.1  christos 	if (ISSET(flags, PRTERA))
    432   1.1  christos 		SET(lflag, ECHOPRT);
    433   1.1  christos 	else
    434   1.1  christos 		CLR(lflag, ECHOPRT);
    435   1.1  christos 	if (ISSET(flags, CRTERA))
    436   1.1  christos 		SET(lflag, ECHOE);
    437   1.1  christos 	else
    438   1.1  christos 		CLR(lflag, ECHOE);
    439   1.1  christos 	/* Nothing we can do with TILDE. */
    440   1.1  christos 	if (ISSET(flags, MDMBUF))
    441   1.1  christos 		SET(cflag, MDMBUF);
    442   1.1  christos 	else
    443   1.1  christos 		CLR(cflag, MDMBUF);
    444   1.1  christos 	if (ISSET(flags, NOHANG))
    445   1.1  christos 		CLR(cflag, HUPCL);
    446   1.1  christos 	else
    447   1.1  christos 		SET(cflag, HUPCL);
    448   1.1  christos 	if (ISSET(flags, CRTKIL))
    449   1.1  christos 		SET(lflag, ECHOKE);
    450   1.1  christos 	else
    451   1.1  christos 		CLR(lflag, ECHOKE);
    452   1.1  christos 	if (ISSET(flags, CTLECH))
    453   1.1  christos 		SET(lflag, ECHOCTL);
    454   1.1  christos 	else
    455   1.1  christos 		CLR(lflag, ECHOCTL);
    456   1.1  christos 	if (!ISSET(flags, DECCTQ))
    457   1.1  christos 		SET(iflag, IXANY);
    458   1.1  christos 	else
    459   1.1  christos 		CLR(iflag, IXANY);
    460   1.1  christos 	CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH);
    461   1.1  christos 	SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
    462   1.1  christos 
    463   1.1  christos 	if (ISSET(flags, RAW|LITOUT|PASS8)) {
    464   1.1  christos 		CLR(cflag, CSIZE);
    465   1.1  christos 		SET(cflag, CS8);
    466   1.1  christos 		if (!ISSET(flags, RAW|PASS8))
    467   1.1  christos 			SET(iflag, ISTRIP);
    468   1.1  christos 		else
    469   1.1  christos 			CLR(iflag, ISTRIP);
    470   1.1  christos 		if (!ISSET(flags, RAW|LITOUT))
    471   1.1  christos 			SET(oflag, OPOST);
    472   1.1  christos 		else
    473   1.1  christos 			CLR(oflag, OPOST);
    474   1.1  christos 	} else {
    475   1.1  christos 		CLR(cflag, CSIZE);
    476   1.1  christos 		SET(cflag, CS7);
    477   1.1  christos 		SET(iflag, ISTRIP);
    478   1.1  christos 		SET(oflag, OPOST);
    479   1.1  christos 	}
    480   1.1  christos 
    481   1.1  christos 	t->c_iflag = iflag;
    482   1.1  christos 	t->c_oflag = oflag;
    483   1.1  christos 	t->c_lflag = lflag;
    484   1.1  christos 	t->c_cflag = cflag;
    485   1.1  christos }
    486   1.4     veego 
    487   1.4     veego #endif /* COMPAT_OLDTTY */
    488