Home | History | Annotate | Line # | Download | only in common
tty_43.c revision 1.1
      1  1.1  christos /*	$NetBSD: tty_43.c,v 1.1 1996/02/02 18:47:57 christos 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.1  christos  *	@(#)tty_compat.c	8.1 (Berkeley) 6/10/93
     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.1  christos #include <sys/param.h>
     42  1.1  christos #include <sys/systm.h>
     43  1.1  christos #include <sys/ioctl.h>
     44  1.1  christos #include <sys/proc.h>
     45  1.1  christos #include <sys/tty.h>
     46  1.1  christos #include <sys/termios.h>
     47  1.1  christos #include <sys/file.h>
     48  1.1  christos #include <sys/conf.h>
     49  1.1  christos #include <sys/kernel.h>
     50  1.1  christos #include <sys/syslog.h>
     51  1.1  christos 
     52  1.1  christos int ttydebug = 0;
     53  1.1  christos 
     54  1.1  christos static struct speedtab compatspeeds[] = {
     55  1.1  christos #define MAX_SPEED	17
     56  1.1  christos 	{ 115200, 17 },
     57  1.1  christos 	{ 57600, 16 },
     58  1.1  christos 	{ 38400, 15 },
     59  1.1  christos 	{ 19200, 14 },
     60  1.1  christos 	{ 9600,	13 },
     61  1.1  christos 	{ 4800,	12 },
     62  1.1  christos 	{ 2400,	11 },
     63  1.1  christos 	{ 1800,	10 },
     64  1.1  christos 	{ 1200,	9 },
     65  1.1  christos 	{ 600,	8 },
     66  1.1  christos 	{ 300,	7 },
     67  1.1  christos 	{ 200,	6 },
     68  1.1  christos 	{ 150,	5 },
     69  1.1  christos 	{ 134,	4 },
     70  1.1  christos 	{ 110,	3 },
     71  1.1  christos 	{ 75,	2 },
     72  1.1  christos 	{ 50,	1 },
     73  1.1  christos 	{ 0,	0 },
     74  1.1  christos 	{ -1,	-1 },
     75  1.1  christos };
     76  1.1  christos static int compatspcodes[] = {
     77  1.1  christos 	0, 50, 75, 110, 134, 150, 200, 300, 600, 1200,
     78  1.1  christos 	1800, 2400, 4800, 9600, 19200, 38400, 57600, 115200
     79  1.1  christos };
     80  1.1  christos 
     81  1.1  christos /* Macros to clear/set/test flags. */
     82  1.1  christos #define	SET(t, f)	(t) |= (f)
     83  1.1  christos #define	CLR(t, f)	(t) &= ~(f)
     84  1.1  christos #define	ISSET(t, f)	((t) & (f))
     85  1.1  christos 
     86  1.1  christos /*ARGSUSED*/
     87  1.1  christos ttcompat(tp, com, data, flag, p)
     88  1.1  christos 	register struct tty *tp;
     89  1.1  christos 	u_long com;
     90  1.1  christos 	caddr_t data;
     91  1.1  christos 	int flag;
     92  1.1  christos 	struct proc *p;
     93  1.1  christos {
     94  1.1  christos 
     95  1.1  christos 	switch (com) {
     96  1.1  christos 	case TIOCGETP: {
     97  1.1  christos 		register struct sgttyb *sg = (struct sgttyb *)data;
     98  1.1  christos 		register u_char *cc = tp->t_cc;
     99  1.1  christos 		register int speed;
    100  1.1  christos 
    101  1.1  christos 		speed = ttspeedtab(tp->t_ospeed, compatspeeds);
    102  1.1  christos 		sg->sg_ospeed = (speed == -1) ? MAX_SPEED : speed;
    103  1.1  christos 		if (tp->t_ispeed == 0)
    104  1.1  christos 			sg->sg_ispeed = sg->sg_ospeed;
    105  1.1  christos 		else {
    106  1.1  christos 			speed = ttspeedtab(tp->t_ispeed, compatspeeds);
    107  1.1  christos 			sg->sg_ispeed = (speed == -1) ? MAX_SPEED : speed;
    108  1.1  christos 		}
    109  1.1  christos 		sg->sg_erase = cc[VERASE];
    110  1.1  christos 		sg->sg_kill = cc[VKILL];
    111  1.1  christos 		sg->sg_flags = ttcompatgetflags(tp);
    112  1.1  christos 		break;
    113  1.1  christos 	}
    114  1.1  christos 
    115  1.1  christos 	case TIOCSETP:
    116  1.1  christos 	case TIOCSETN: {
    117  1.1  christos 		register struct sgttyb *sg = (struct sgttyb *)data;
    118  1.1  christos 		struct termios term;
    119  1.1  christos 		int speed;
    120  1.1  christos 
    121  1.1  christos 		term = tp->t_termios;
    122  1.1  christos 		if ((speed = sg->sg_ispeed) > MAX_SPEED || speed < 0)
    123  1.1  christos 			term.c_ispeed = speed;
    124  1.1  christos 		else
    125  1.1  christos 			term.c_ispeed = compatspcodes[speed];
    126  1.1  christos 		if ((speed = sg->sg_ospeed) > MAX_SPEED || speed < 0)
    127  1.1  christos 			term.c_ospeed = speed;
    128  1.1  christos 		else
    129  1.1  christos 			term.c_ospeed = compatspcodes[speed];
    130  1.1  christos 		term.c_cc[VERASE] = sg->sg_erase;
    131  1.1  christos 		term.c_cc[VKILL] = sg->sg_kill;
    132  1.1  christos 		tp->t_flags = (ttcompatgetflags(tp)&0xffff0000) | (sg->sg_flags&0xffff);
    133  1.1  christos 		ttcompatsetflags(tp, &term);
    134  1.1  christos 		return (ttioctl(tp, com == TIOCSETP ? TIOCSETAF : TIOCSETA,
    135  1.1  christos 			(caddr_t)&term, flag, p));
    136  1.1  christos 	}
    137  1.1  christos 
    138  1.1  christos 	case TIOCGETC: {
    139  1.1  christos 		struct tchars *tc = (struct tchars *)data;
    140  1.1  christos 		register u_char *cc = tp->t_cc;
    141  1.1  christos 
    142  1.1  christos 		tc->t_intrc = cc[VINTR];
    143  1.1  christos 		tc->t_quitc = cc[VQUIT];
    144  1.1  christos 		tc->t_startc = cc[VSTART];
    145  1.1  christos 		tc->t_stopc = cc[VSTOP];
    146  1.1  christos 		tc->t_eofc = cc[VEOF];
    147  1.1  christos 		tc->t_brkc = cc[VEOL];
    148  1.1  christos 		break;
    149  1.1  christos 	}
    150  1.1  christos 	case TIOCSETC: {
    151  1.1  christos 		struct tchars *tc = (struct tchars *)data;
    152  1.1  christos 		register u_char *cc = tp->t_cc;
    153  1.1  christos 
    154  1.1  christos 		cc[VINTR] = tc->t_intrc;
    155  1.1  christos 		cc[VQUIT] = tc->t_quitc;
    156  1.1  christos 		cc[VSTART] = tc->t_startc;
    157  1.1  christos 		cc[VSTOP] = tc->t_stopc;
    158  1.1  christos 		cc[VEOF] = tc->t_eofc;
    159  1.1  christos 		cc[VEOL] = tc->t_brkc;
    160  1.1  christos 		if (tc->t_brkc == -1)
    161  1.1  christos 			cc[VEOL2] = _POSIX_VDISABLE;
    162  1.1  christos 		break;
    163  1.1  christos 	}
    164  1.1  christos 	case TIOCSLTC: {
    165  1.1  christos 		struct ltchars *ltc = (struct ltchars *)data;
    166  1.1  christos 		register u_char *cc = tp->t_cc;
    167  1.1  christos 
    168  1.1  christos 		cc[VSUSP] = ltc->t_suspc;
    169  1.1  christos 		cc[VDSUSP] = ltc->t_dsuspc;
    170  1.1  christos 		cc[VREPRINT] = ltc->t_rprntc;
    171  1.1  christos 		cc[VDISCARD] = ltc->t_flushc;
    172  1.1  christos 		cc[VWERASE] = ltc->t_werasc;
    173  1.1  christos 		cc[VLNEXT] = ltc->t_lnextc;
    174  1.1  christos 		break;
    175  1.1  christos 	}
    176  1.1  christos 	case TIOCGLTC: {
    177  1.1  christos 		struct ltchars *ltc = (struct ltchars *)data;
    178  1.1  christos 		register u_char *cc = tp->t_cc;
    179  1.1  christos 
    180  1.1  christos 		ltc->t_suspc = cc[VSUSP];
    181  1.1  christos 		ltc->t_dsuspc = cc[VDSUSP];
    182  1.1  christos 		ltc->t_rprntc = cc[VREPRINT];
    183  1.1  christos 		ltc->t_flushc = cc[VDISCARD];
    184  1.1  christos 		ltc->t_werasc = cc[VWERASE];
    185  1.1  christos 		ltc->t_lnextc = cc[VLNEXT];
    186  1.1  christos 		break;
    187  1.1  christos 	}
    188  1.1  christos 	case TIOCLBIS:
    189  1.1  christos 	case TIOCLBIC:
    190  1.1  christos 	case TIOCLSET: {
    191  1.1  christos 		struct termios term;
    192  1.1  christos 		int flags;
    193  1.1  christos 
    194  1.1  christos 		term = tp->t_termios;
    195  1.1  christos 		flags = ttcompatgetflags(tp);
    196  1.1  christos 		switch (com) {
    197  1.1  christos 		case TIOCLSET:
    198  1.1  christos 			tp->t_flags = (flags&0xffff) | (*(int *)data<<16);
    199  1.1  christos 			break;
    200  1.1  christos 		case TIOCLBIS:
    201  1.1  christos 			tp->t_flags = flags | (*(int *)data<<16);
    202  1.1  christos 			break;
    203  1.1  christos 		case TIOCLBIC:
    204  1.1  christos 			tp->t_flags = flags & ~(*(int *)data<<16);
    205  1.1  christos 			break;
    206  1.1  christos 		}
    207  1.1  christos 		ttcompatsetlflags(tp, &term);
    208  1.1  christos 		return (ttioctl(tp, TIOCSETA, (caddr_t)&term, flag, p));
    209  1.1  christos 	}
    210  1.1  christos 	case TIOCLGET:
    211  1.1  christos 		*(int *)data = ttcompatgetflags(tp)>>16;
    212  1.1  christos 		if (ttydebug)
    213  1.1  christos 			printf("CLGET: returning %x\n", *(int *)data);
    214  1.1  christos 		break;
    215  1.1  christos 
    216  1.1  christos 	case OTIOCGETD:
    217  1.1  christos 		*(int *)data = tp->t_line ? tp->t_line : 2;
    218  1.1  christos 		break;
    219  1.1  christos 
    220  1.1  christos 	case OTIOCSETD: {
    221  1.1  christos 		int ldisczero = 0;
    222  1.1  christos 
    223  1.1  christos 		return (ttioctl(tp, TIOCSETD,
    224  1.1  christos 			*(int *)data == 2 ? (caddr_t)&ldisczero : data, flag,
    225  1.1  christos 			p));
    226  1.1  christos 	    }
    227  1.1  christos 
    228  1.1  christos 	case OTIOCCONS:
    229  1.1  christos 		*(int *)data = 1;
    230  1.1  christos 		return (ttioctl(tp, TIOCCONS, data, flag, p));
    231  1.1  christos 
    232  1.1  christos 	case TIOCHPCL:
    233  1.1  christos 		SET(tp->t_cflag, HUPCL);
    234  1.1  christos 		break;
    235  1.1  christos 
    236  1.1  christos 	case TIOCGSID:
    237  1.1  christos 		if (tp->t_session == NULL)
    238  1.1  christos 			return ENOTTY;
    239  1.1  christos 
    240  1.1  christos 		if (tp->t_session->s_leader == NULL)
    241  1.1  christos 			return ENOTTY;
    242  1.1  christos 
    243  1.1  christos 		*(int *) data =  tp->t_session->s_leader->p_pid;
    244  1.1  christos 		break;
    245  1.1  christos 
    246  1.1  christos 	default:
    247  1.1  christos 		return (-1);
    248  1.1  christos 	}
    249  1.1  christos 	return (0);
    250  1.1  christos }
    251  1.1  christos 
    252  1.1  christos int
    253  1.1  christos ttcompatgetflags(tp)
    254  1.1  christos 	register struct tty *tp;
    255  1.1  christos {
    256  1.1  christos 	register tcflag_t iflag = tp->t_iflag;
    257  1.1  christos 	register tcflag_t lflag = tp->t_lflag;
    258  1.1  christos 	register tcflag_t oflag = tp->t_oflag;
    259  1.1  christos 	register tcflag_t cflag = tp->t_cflag;
    260  1.1  christos 	register int flags = 0;
    261  1.1  christos 
    262  1.1  christos 	if (ISSET(iflag, IXOFF))
    263  1.1  christos 		SET(flags, TANDEM);
    264  1.1  christos 	if (ISSET(iflag, ICRNL) || ISSET(oflag, ONLCR))
    265  1.1  christos 		SET(flags, CRMOD);
    266  1.1  christos 	if (ISSET(cflag, PARENB)) {
    267  1.1  christos 		if (ISSET(iflag, INPCK)) {
    268  1.1  christos 			if (ISSET(cflag, PARODD))
    269  1.1  christos 				SET(flags, ODDP);
    270  1.1  christos 			else
    271  1.1  christos 				SET(flags, EVENP);
    272  1.1  christos 		} else
    273  1.1  christos 			SET(flags, ANYP);
    274  1.1  christos 	}
    275  1.1  christos 
    276  1.1  christos 	if (!ISSET(lflag, ICANON)) {
    277  1.1  christos 		/* fudge */
    278  1.1  christos 		if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) ||
    279  1.1  christos 		    ISSET(cflag, PARENB))
    280  1.1  christos 			SET(flags, CBREAK);
    281  1.1  christos 		else
    282  1.1  christos 			SET(flags, RAW);
    283  1.1  christos 	}
    284  1.1  christos 
    285  1.1  christos 	if (ISSET(flags, RAW))
    286  1.1  christos 		SET(flags, ISSET(tp->t_flags, LITOUT|PASS8));
    287  1.1  christos 	else if (ISSET(cflag, CSIZE) == CS8) {
    288  1.1  christos 		if (!ISSET(oflag, OPOST))
    289  1.1  christos 			SET(flags, LITOUT);
    290  1.1  christos 		if (!ISSET(iflag, ISTRIP))
    291  1.1  christos 			SET(flags, PASS8);
    292  1.1  christos 	}
    293  1.1  christos 
    294  1.1  christos 	if (ISSET(cflag, MDMBUF))
    295  1.1  christos 		SET(flags, MDMBUF);
    296  1.1  christos 	if (!ISSET(cflag, HUPCL))
    297  1.1  christos 		SET(flags, NOHANG);
    298  1.1  christos 	if (ISSET(oflag, OXTABS))
    299  1.1  christos 		SET(flags, XTABS);
    300  1.1  christos 	if (ISSET(lflag, ECHOE))
    301  1.1  christos 		SET(flags, CRTERA|CRTBS);
    302  1.1  christos 	if (ISSET(lflag, ECHOKE))
    303  1.1  christos 		SET(flags, CRTKIL|CRTBS);
    304  1.1  christos 	if (ISSET(lflag, ECHOPRT))
    305  1.1  christos 		SET(flags, PRTERA);
    306  1.1  christos 	if (ISSET(lflag, ECHOCTL))
    307  1.1  christos 		SET(flags, CTLECH);
    308  1.1  christos 	if (!ISSET(iflag, IXANY))
    309  1.1  christos 		SET(flags, DECCTQ);
    310  1.1  christos 	SET(flags, ISSET(lflag, ECHO|TOSTOP|FLUSHO|PENDIN|NOFLSH));
    311  1.1  christos 	if (ttydebug)
    312  1.1  christos 		printf("getflags: %x\n", flags);
    313  1.1  christos 	return (flags);
    314  1.1  christos }
    315  1.1  christos 
    316  1.1  christos ttcompatsetflags(tp, t)
    317  1.1  christos 	register struct tty *tp;
    318  1.1  christos 	register struct termios *t;
    319  1.1  christos {
    320  1.1  christos 	register int flags = tp->t_flags;
    321  1.1  christos 	register tcflag_t iflag = t->c_iflag;
    322  1.1  christos 	register tcflag_t oflag = t->c_oflag;
    323  1.1  christos 	register tcflag_t lflag = t->c_lflag;
    324  1.1  christos 	register tcflag_t cflag = t->c_cflag;
    325  1.1  christos 
    326  1.1  christos 	if (ISSET(flags, TANDEM))
    327  1.1  christos 		SET(iflag, IXOFF);
    328  1.1  christos 	else
    329  1.1  christos 		CLR(iflag, IXOFF);
    330  1.1  christos 	if (ISSET(flags, ECHO))
    331  1.1  christos 		SET(lflag, ECHO);
    332  1.1  christos 	else
    333  1.1  christos 		CLR(lflag, ECHO);
    334  1.1  christos 	if (ISSET(flags, CRMOD)) {
    335  1.1  christos 		SET(iflag, ICRNL);
    336  1.1  christos 		SET(oflag, ONLCR);
    337  1.1  christos 	} else {
    338  1.1  christos 		CLR(iflag, ICRNL);
    339  1.1  christos 		CLR(oflag, ONLCR);
    340  1.1  christos 	}
    341  1.1  christos 	if (ISSET(flags, XTABS))
    342  1.1  christos 		SET(oflag, OXTABS);
    343  1.1  christos 	else
    344  1.1  christos 		CLR(oflag, OXTABS);
    345  1.1  christos 
    346  1.1  christos 
    347  1.1  christos 	if (ISSET(flags, RAW)) {
    348  1.1  christos 		iflag &= IXOFF;
    349  1.1  christos 		CLR(lflag, ISIG|ICANON|IEXTEN);
    350  1.1  christos 		CLR(cflag, PARENB);
    351  1.1  christos 	} else {
    352  1.1  christos 		SET(iflag, BRKINT|IXON|IMAXBEL);
    353  1.1  christos 		SET(lflag, ISIG|IEXTEN);
    354  1.1  christos 		if (ISSET(flags, CBREAK))
    355  1.1  christos 			CLR(lflag, ICANON);
    356  1.1  christos 		else
    357  1.1  christos 			SET(lflag, ICANON);
    358  1.1  christos 		switch (ISSET(flags, ANYP)) {
    359  1.1  christos 		case 0:
    360  1.1  christos 			CLR(cflag, PARENB);
    361  1.1  christos 			break;
    362  1.1  christos 		case ANYP:
    363  1.1  christos 			SET(cflag, PARENB);
    364  1.1  christos 			CLR(iflag, INPCK);
    365  1.1  christos 			break;
    366  1.1  christos 		case EVENP:
    367  1.1  christos 			SET(cflag, PARENB);
    368  1.1  christos 			SET(iflag, INPCK);
    369  1.1  christos 			CLR(cflag, PARODD);
    370  1.1  christos 			break;
    371  1.1  christos 		case ODDP:
    372  1.1  christos 			SET(cflag, PARENB);
    373  1.1  christos 			SET(iflag, INPCK);
    374  1.1  christos 			SET(cflag, PARODD);
    375  1.1  christos 			break;
    376  1.1  christos 		}
    377  1.1  christos 	}
    378  1.1  christos 
    379  1.1  christos 	if (ISSET(flags, RAW|LITOUT|PASS8)) {
    380  1.1  christos 		CLR(cflag, CSIZE);
    381  1.1  christos 		SET(cflag, CS8);
    382  1.1  christos 		if (!ISSET(flags, RAW|PASS8))
    383  1.1  christos 			SET(iflag, ISTRIP);
    384  1.1  christos 		else
    385  1.1  christos 			CLR(iflag, ISTRIP);
    386  1.1  christos 		if (!ISSET(flags, RAW|LITOUT))
    387  1.1  christos 			SET(oflag, OPOST);
    388  1.1  christos 		else
    389  1.1  christos 			CLR(oflag, OPOST);
    390  1.1  christos 	} else {
    391  1.1  christos 		CLR(cflag, CSIZE);
    392  1.1  christos 		SET(cflag, CS7);
    393  1.1  christos 		SET(iflag, ISTRIP);
    394  1.1  christos 		SET(oflag, OPOST);
    395  1.1  christos 	}
    396  1.1  christos 
    397  1.1  christos 	t->c_iflag = iflag;
    398  1.1  christos 	t->c_oflag = oflag;
    399  1.1  christos 	t->c_lflag = lflag;
    400  1.1  christos 	t->c_cflag = cflag;
    401  1.1  christos }
    402  1.1  christos 
    403  1.1  christos ttcompatsetlflags(tp, t)
    404  1.1  christos 	register struct tty *tp;
    405  1.1  christos 	register struct termios *t;
    406  1.1  christos {
    407  1.1  christos 	register int flags = tp->t_flags;
    408  1.1  christos 	register tcflag_t iflag = t->c_iflag;
    409  1.1  christos 	register tcflag_t oflag = t->c_oflag;
    410  1.1  christos 	register tcflag_t lflag = t->c_lflag;
    411  1.1  christos 	register tcflag_t cflag = t->c_cflag;
    412  1.1  christos 
    413  1.1  christos 	/* Nothing we can do with CRTBS. */
    414  1.1  christos 	if (ISSET(flags, PRTERA))
    415  1.1  christos 		SET(lflag, ECHOPRT);
    416  1.1  christos 	else
    417  1.1  christos 		CLR(lflag, ECHOPRT);
    418  1.1  christos 	if (ISSET(flags, CRTERA))
    419  1.1  christos 		SET(lflag, ECHOE);
    420  1.1  christos 	else
    421  1.1  christos 		CLR(lflag, ECHOE);
    422  1.1  christos 	/* Nothing we can do with TILDE. */
    423  1.1  christos 	if (ISSET(flags, MDMBUF))
    424  1.1  christos 		SET(cflag, MDMBUF);
    425  1.1  christos 	else
    426  1.1  christos 		CLR(cflag, MDMBUF);
    427  1.1  christos 	if (ISSET(flags, NOHANG))
    428  1.1  christos 		CLR(cflag, HUPCL);
    429  1.1  christos 	else
    430  1.1  christos 		SET(cflag, HUPCL);
    431  1.1  christos 	if (ISSET(flags, CRTKIL))
    432  1.1  christos 		SET(lflag, ECHOKE);
    433  1.1  christos 	else
    434  1.1  christos 		CLR(lflag, ECHOKE);
    435  1.1  christos 	if (ISSET(flags, CTLECH))
    436  1.1  christos 		SET(lflag, ECHOCTL);
    437  1.1  christos 	else
    438  1.1  christos 		CLR(lflag, ECHOCTL);
    439  1.1  christos 	if (!ISSET(flags, DECCTQ))
    440  1.1  christos 		SET(iflag, IXANY);
    441  1.1  christos 	else
    442  1.1  christos 		CLR(iflag, IXANY);
    443  1.1  christos 	CLR(lflag, TOSTOP|FLUSHO|PENDIN|NOFLSH);
    444  1.1  christos 	SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
    445  1.1  christos 
    446  1.1  christos 	if (ISSET(flags, RAW|LITOUT|PASS8)) {
    447  1.1  christos 		CLR(cflag, CSIZE);
    448  1.1  christos 		SET(cflag, CS8);
    449  1.1  christos 		if (!ISSET(flags, RAW|PASS8))
    450  1.1  christos 			SET(iflag, ISTRIP);
    451  1.1  christos 		else
    452  1.1  christos 			CLR(iflag, ISTRIP);
    453  1.1  christos 		if (!ISSET(flags, RAW|LITOUT))
    454  1.1  christos 			SET(oflag, OPOST);
    455  1.1  christos 		else
    456  1.1  christos 			CLR(oflag, OPOST);
    457  1.1  christos 	} else {
    458  1.1  christos 		CLR(cflag, CSIZE);
    459  1.1  christos 		SET(cflag, CS7);
    460  1.1  christos 		SET(iflag, ISTRIP);
    461  1.1  christos 		SET(oflag, OPOST);
    462  1.1  christos 	}
    463  1.1  christos 
    464  1.1  christos 	t->c_iflag = iflag;
    465  1.1  christos 	t->c_oflag = oflag;
    466  1.1  christos 	t->c_lflag = lflag;
    467  1.1  christos 	t->c_cflag = cflag;
    468  1.1  christos }
    469