1995-10-03 18:02:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1995
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* ttcompat.c -- convert sgtty flags to termios
|
|
|
|
* originally from /sys/kern/tty_compat.c
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <sys/ioctl_compat.h>
|
|
|
|
#include <termios.h>
|
|
|
|
#include <syslog.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "extern.h"
|
|
|
|
|
1995-10-05 10:39:39 +03:00
|
|
|
/* Macros to clear/set/test flags. */
|
|
|
|
#define SET(t, f) (t) |= (f)
|
|
|
|
#define CLR(t, f) (t) &= ~(f)
|
|
|
|
#define ISSET(t, f) ((t) & (f))
|
|
|
|
|
1995-10-05 11:20:20 +03:00
|
|
|
static int
|
|
|
|
sttygetoflags(tp)
|
|
|
|
struct termios *tp;
|
|
|
|
{
|
1995-10-05 11:23:18 +03:00
|
|
|
register tcflag_t iflag = tp->c_iflag;
|
|
|
|
register tcflag_t lflag = tp->c_lflag;
|
|
|
|
register tcflag_t oflag = tp->c_oflag;
|
|
|
|
register tcflag_t cflag = tp->c_cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
register int flags = 0;
|
|
|
|
|
|
|
|
if (ISSET(cflag, PARENB)) {
|
|
|
|
if (ISSET(iflag, INPCK)) {
|
|
|
|
if (ISSET(cflag, PARODD))
|
|
|
|
SET(flags, ODDP);
|
|
|
|
else
|
|
|
|
SET(flags, EVENP);
|
|
|
|
} else
|
|
|
|
SET(flags, EVENP|ODDP);
|
|
|
|
}
|
|
|
|
if (ISSET(cflag, CSIZE) == CS8) {
|
|
|
|
if (!ISSET(iflag, ISTRIP))
|
|
|
|
SET(flags, PASS8);
|
|
|
|
if (!ISSET(oflag, OPOST))
|
|
|
|
SET(flags, LITOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!ISSET(lflag, ICANON)) {
|
|
|
|
/* fudge */
|
|
|
|
if (ISSET(iflag, IXON) || ISSET(lflag, ISIG|IEXTEN) ||
|
|
|
|
ISSET(cflag, PARENB))
|
|
|
|
SET(flags, CBREAK);
|
|
|
|
else
|
|
|
|
SET(flags, RAW);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
sttysetoflags(tp, flags)
|
|
|
|
struct termios *tp;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
register tcflag_t iflag = tp->c_iflag;
|
|
|
|
register tcflag_t oflag = tp->c_oflag;
|
|
|
|
register tcflag_t lflag = tp->c_lflag;
|
|
|
|
register tcflag_t cflag = tp->c_cflag;
|
|
|
|
|
|
|
|
switch (ISSET(flags, ANYP)) {
|
|
|
|
case EVENP:
|
|
|
|
SET(iflag, INPCK);
|
|
|
|
CLR(cflag, PARODD);
|
|
|
|
break;
|
|
|
|
case ODDP:
|
|
|
|
SET(iflag, INPCK);
|
|
|
|
SET(cflag, PARODD);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
CLR(iflag, INPCK);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ISSET(flags, RAW|LITOUT|PASS8)) {
|
|
|
|
CLR(cflag, CSIZE|PARENB);
|
|
|
|
SET(cflag, CS8);
|
|
|
|
if (!ISSET(flags, RAW|PASS8))
|
|
|
|
SET(iflag, ISTRIP);
|
|
|
|
else
|
|
|
|
CLR(iflag, ISTRIP);
|
|
|
|
if (!ISSET(flags, RAW|LITOUT))
|
|
|
|
SET(oflag, OPOST);
|
|
|
|
else
|
|
|
|
CLR(oflag, OPOST);
|
|
|
|
} else {
|
|
|
|
CLR(cflag, CSIZE);
|
|
|
|
SET(cflag, CS7|PARENB);
|
|
|
|
SET(iflag, ISTRIP);
|
|
|
|
SET(oflag, OPOST);
|
|
|
|
}
|
|
|
|
|
|
|
|
tp->c_iflag = iflag;
|
|
|
|
tp->c_oflag = oflag;
|
|
|
|
tp->c_lflag = lflag;
|
|
|
|
tp->c_cflag = cflag;
|
|
|
|
}
|
|
|
|
|
1995-10-03 18:02:17 +03:00
|
|
|
void
|
|
|
|
sttyclearflags(tp, flags)
|
1995-10-05 10:47:32 +03:00
|
|
|
struct termios *tp;
|
|
|
|
int flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
{
|
1995-10-05 10:47:32 +03:00
|
|
|
register tcflag_t iflag = tp->c_iflag;
|
|
|
|
register tcflag_t oflag = tp->c_oflag;
|
|
|
|
register tcflag_t lflag = tp->c_lflag;
|
|
|
|
register tcflag_t cflag = tp->c_cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
register int oflags = sttygetoflags(tp) & ~flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, TANDEM))
|
|
|
|
CLR(iflag, IXOFF);
|
|
|
|
if (ISSET(flags, ECHO))
|
|
|
|
CLR(lflag, ECHO);
|
|
|
|
if (ISSET(flags, CRMOD)) {
|
|
|
|
CLR(iflag, ICRNL);
|
|
|
|
CLR(oflag, ONLCR);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, XTABS))
|
|
|
|
CLR(oflag, OXTABS);
|
1995-10-03 18:02:17 +03:00
|
|
|
|
|
|
|
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, RAW)) {
|
|
|
|
SET(iflag, BRKINT|IXON|IMAXBEL);
|
|
|
|
SET(lflag, ISIG|IEXTEN);
|
|
|
|
if (ISSET(flags, CBREAK))
|
|
|
|
CLR(lflag, ICANON);
|
1995-10-03 18:02:17 +03:00
|
|
|
else
|
1995-10-05 10:39:39 +03:00
|
|
|
SET(lflag, ICANON);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
tp->c_iflag = iflag;
|
|
|
|
tp->c_oflag = oflag;
|
|
|
|
tp->c_lflag = lflag;
|
|
|
|
tp->c_cflag = cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
|
|
|
|
sttysetoflags(tp, oflags);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttysetflags(tp, flags)
|
1995-10-05 10:47:32 +03:00
|
|
|
struct termios *tp;
|
|
|
|
int flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
{
|
1995-10-05 10:47:32 +03:00
|
|
|
register tcflag_t iflag = tp->c_iflag;
|
|
|
|
register tcflag_t oflag = tp->c_oflag;
|
|
|
|
register tcflag_t lflag = tp->c_lflag;
|
|
|
|
register tcflag_t cflag = tp->c_cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
register int oflags = sttygetoflags(tp) | flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, TANDEM))
|
|
|
|
SET(iflag, IXOFF);
|
|
|
|
if (ISSET(flags, ECHO))
|
|
|
|
SET(lflag, ECHO);
|
|
|
|
if (ISSET(flags, CRMOD)) {
|
|
|
|
SET(iflag, ICRNL);
|
|
|
|
SET(oflag, ONLCR);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, XTABS))
|
|
|
|
SET(oflag, OXTABS);
|
1995-10-03 18:02:17 +03:00
|
|
|
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, RAW)) {
|
1995-10-05 10:42:30 +03:00
|
|
|
iflag &= IXOFF;
|
1995-10-05 10:39:39 +03:00
|
|
|
CLR(lflag, ISIG|ICANON|IEXTEN);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
tp->c_iflag = iflag;
|
|
|
|
tp->c_oflag = oflag;
|
|
|
|
tp->c_lflag = lflag;
|
|
|
|
tp->c_cflag = cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
|
|
|
|
sttysetoflags(tp, oflags);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttyclearlflags(tp, flags)
|
1995-10-05 10:47:32 +03:00
|
|
|
struct termios *tp;
|
|
|
|
int flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
{
|
1995-10-05 10:47:32 +03:00
|
|
|
register tcflag_t iflag = tp->c_iflag;
|
|
|
|
register tcflag_t oflag = tp->c_oflag;
|
|
|
|
register tcflag_t lflag = tp->c_lflag;
|
|
|
|
register tcflag_t cflag = tp->c_cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
register int oflags = sttygetoflags(tp) & ~flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
|
|
|
|
/* Nothing we can do with CRTBS. */
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, PRTERA))
|
|
|
|
CLR(lflag, ECHOPRT);
|
|
|
|
if (ISSET(flags, CRTERA))
|
|
|
|
CLR(lflag, ECHOE);
|
1995-10-03 18:02:17 +03:00
|
|
|
/* Nothing we can do with TILDE. */
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, MDMBUF))
|
|
|
|
CLR(cflag, MDMBUF);
|
|
|
|
if (ISSET(flags, NOHANG))
|
|
|
|
SET(cflag, HUPCL);
|
|
|
|
if (ISSET(flags, CRTKIL))
|
|
|
|
CLR(lflag, ECHOKE);
|
|
|
|
if (ISSET(flags, CTLECH))
|
|
|
|
CLR(lflag, ECHOCTL);
|
1995-10-05 11:01:29 +03:00
|
|
|
if (ISSET(flags, DECCTQ))
|
|
|
|
SET(iflag, IXANY);
|
1995-10-05 10:39:39 +03:00
|
|
|
CLR(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
|
|
|
|
|
1995-10-03 18:02:17 +03:00
|
|
|
tp->c_iflag = iflag;
|
|
|
|
tp->c_oflag = oflag;
|
|
|
|
tp->c_lflag = lflag;
|
|
|
|
tp->c_cflag = cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
|
|
|
|
sttysetoflags(tp, oflags);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sttysetlflags(tp, flags)
|
1995-10-05 10:47:32 +03:00
|
|
|
struct termios *tp;
|
|
|
|
int flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
{
|
1995-10-05 10:47:32 +03:00
|
|
|
register tcflag_t iflag = tp->c_iflag;
|
|
|
|
register tcflag_t oflag = tp->c_oflag;
|
|
|
|
register tcflag_t lflag = tp->c_lflag;
|
|
|
|
register tcflag_t cflag = tp->c_cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
register int oflags = sttygetoflags(tp) | flags;
|
1995-10-03 18:02:17 +03:00
|
|
|
|
|
|
|
/* Nothing we can do with CRTBS. */
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, PRTERA))
|
|
|
|
SET(lflag, ECHOPRT);
|
|
|
|
if (ISSET(flags, CRTERA))
|
|
|
|
SET(lflag, ECHOE);
|
1995-10-03 18:02:17 +03:00
|
|
|
/* Nothing we can do with TILDE. */
|
1995-10-05 10:39:39 +03:00
|
|
|
if (ISSET(flags, MDMBUF))
|
|
|
|
SET(cflag, MDMBUF);
|
|
|
|
if (ISSET(flags, NOHANG))
|
|
|
|
CLR(cflag, HUPCL);
|
|
|
|
if (ISSET(flags, CRTKIL))
|
|
|
|
SET(lflag, ECHOKE);
|
|
|
|
if (ISSET(flags, CTLECH))
|
|
|
|
SET(lflag, ECHOCTL);
|
1995-10-05 11:01:29 +03:00
|
|
|
if (ISSET(flags, DECCTQ))
|
|
|
|
CLR(iflag, IXANY);
|
1995-10-05 10:39:39 +03:00
|
|
|
SET(lflag, ISSET(flags, TOSTOP|FLUSHO|PENDIN|NOFLSH));
|
|
|
|
|
1995-10-03 18:02:17 +03:00
|
|
|
tp->c_iflag = iflag;
|
|
|
|
tp->c_oflag = oflag;
|
|
|
|
tp->c_lflag = lflag;
|
|
|
|
tp->c_cflag = cflag;
|
1995-10-05 11:20:20 +03:00
|
|
|
|
|
|
|
sttysetoflags(tp, oflags);
|
1995-10-03 18:02:17 +03:00
|
|
|
}
|