* Copyright (c) 1988 University of Utah.
* Copyright (c) 1990 The Regents of the University of California.
* This code is derived from software contributed to Berkeley by
* the Systems Programming Group of the University of Utah Computer
* %sccs.include.redist.c%
* from: Utah $Hdr: hpux_tty.c 1.1 90/07/09$
* @(#)hpux_tty.c 7.7 (Berkeley) %G%
* stty/gtty/termio emulation stuff
#include "sys/filedesc.h"
* Map BSD/POSIX style termios info to and from SYS5 style termio stuff.
hpuxtermio(fp
, com
, data
)
int line
, error
, (*ioctlrout
)();
register struct hpuxtermio
*tiop
;
ioctlrout
= fp
->f_ops
->fo_ioctl
;
tiop
= (struct hpuxtermio
*)data
;
bzero(data
, sizeof(struct hpuxtermio
));
if (error
= (*ioctlrout
)(fp
, TIOCGETA
, (caddr_t
)&tios
))
* Same through ICRNL, no BSD equivs for IUCLC, IENQAK
tiop
->c_iflag
= tios
.c_iflag
& 0x1ff;
tiop
->c_iflag
|= TIO_IXON
;
if (tios
.c_iflag
& IXOFF
)
tiop
->c_iflag
|= TIO_IXOFF
;
if (tios
.c_iflag
& IXANY
)
tiop
->c_iflag
|= TIO_IXANY
;
* No BSD equivs for OLCUC/OCRNL/ONOCR/ONLRET/OFILL/OFDEL
if (tios
.c_oflag
& OPOST
)
tiop
->c_oflag
|= TIO_OPOST
;
if (tios
.c_oflag
& ONLCR
)
tiop
->c_oflag
|= TIO_ONLCR
;
if (tios
.c_oflag
& OXTABS
)
tiop
->c_oflag
|= TIO_TAB3
;
* Baud from ospeed, rest from cflag.
tiop
->c_cflag
= bsdtohpuxbaud(tios
.c_ospeed
);
switch (tios
.c_cflag
& CSIZE
) {
tiop
->c_cflag
|= TIO_CS5
; break;
tiop
->c_cflag
|= TIO_CS6
; break;
tiop
->c_cflag
|= TIO_CS7
; break;
tiop
->c_cflag
|= TIO_CS8
; break;
if (tios
.c_cflag
& CSTOPB
)
tiop
->c_cflag
|= TIO_CSTOPB
;
if (tios
.c_cflag
& CREAD
)
tiop
->c_cflag
|= TIO_CREAD
;
if (tios
.c_cflag
& PARENB
)
tiop
->c_cflag
|= TIO_PARENB
;
if (tios
.c_cflag
& PARODD
)
tiop
->c_cflag
|= TIO_PARODD
;
if (tios
.c_cflag
& HUPCL
)
tiop
->c_cflag
|= TIO_HUPCL
;
if (tios
.c_cflag
& CLOCAL
)
tiop
->c_cflag
|= TIO_CLOCAL
;
* No BSD equiv for XCASE.
if (tios
.c_lflag
& ECHOE
)
tiop
->c_lflag
|= TIO_ECHOE
;
if (tios
.c_lflag
& ECHOK
)
tiop
->c_lflag
|= TIO_ECHOK
;
tiop
->c_lflag
|= TIO_ECHO
;
if (tios
.c_lflag
& ECHONL
)
tiop
->c_lflag
|= TIO_ECHONL
;
tiop
->c_lflag
|= TIO_ISIG
;
if (tios
.c_lflag
& ICANON
)
tiop
->c_lflag
|= TIO_ICANON
;
if (tios
.c_lflag
& NOFLSH
)
tiop
->c_lflag
|= TIO_NOFLSH
;
(void) (*ioctlrout
)(fp
, TIOCGETD
, (caddr_t
)&line
);
tiop
->c_cc
[HPUXVINTR
] = tios
.c_cc
[VINTR
];
tiop
->c_cc
[HPUXVQUIT
] = tios
.c_cc
[VQUIT
];
tiop
->c_cc
[HPUXVERASE
] = tios
.c_cc
[VERASE
];
tiop
->c_cc
[HPUXVKILL
] = tios
.c_cc
[VKILL
];
if (tiop
->c_lflag
& TIO_ICANON
) {
tiop
->c_cc
[HPUXVEOF
] = tios
.c_cc
[VEOF
];
tiop
->c_cc
[HPUXVEOL
] = tios
.c_cc
[VEOL
];
tiop
->c_cc
[HPUXVMIN
] = tios
.c_cc
[VMIN
];
tiop
->c_cc
[HPUXVTIME
] = tios
.c_cc
[VTIME
];
* Get old characteristics and determine if we are a tty.
if (error
= (*ioctlrout
)(fp
, TIOCGETA
, (caddr_t
)&tios
))
* Same through ICRNL, no HP-UX equiv for IMAXBEL
tios
.c_iflag
&= ~(IXON
|IXOFF
|IXANY
|0x1ff);
tios
.c_iflag
|= tiop
->c_iflag
& 0x1ff;
if (tiop
->c_iflag
& TIO_IXON
)
if (tiop
->c_iflag
& TIO_IXOFF
)
if (tiop
->c_iflag
& TIO_IXANY
)
* No HP-UX equiv for ONOEOT
tios
.c_oflag
&= ~(OPOST
|ONLCR
|OXTABS
);
if (tiop
->c_oflag
& TIO_OPOST
)
if (tiop
->c_oflag
& TIO_ONLCR
)
if (tiop
->c_oflag
& TIO_TAB3
)
* No HP-UX equiv for CCTS_OFLOW/CCTS_IFLOW/MDMBUF
~(CSIZE
|CSTOPB
|CREAD
|PARENB
|PARODD
|HUPCL
|CLOCAL
);
switch (tiop
->c_cflag
& TIO_CSIZE
) {
tios
.c_cflag
|= CS5
; break;
tios
.c_cflag
|= CS6
; break;
tios
.c_cflag
|= CS7
; break;
tios
.c_cflag
|= CS8
; break;
if (tiop
->c_cflag
& TIO_CSTOPB
)
if (tiop
->c_cflag
& TIO_CREAD
)
if (tiop
->c_cflag
& TIO_PARENB
)
if (tiop
->c_cflag
& TIO_PARODD
)
if (tiop
->c_cflag
& TIO_HUPCL
)
if (tiop
->c_cflag
& TIO_CLOCAL
)
* No HP-UX equiv for ECHOKE/ECHOPRT/ECHOCTL
* IEXTEN treated as part of ICANON
tios
.c_lflag
&= ~(ECHOE
|ECHOK
|ECHO
|ISIG
|ICANON
|IEXTEN
|NOFLSH
);
if (tiop
->c_lflag
& TIO_ECHOE
)
if (tiop
->c_lflag
& TIO_ECHOK
)
if (tiop
->c_lflag
& TIO_ECHO
)
if (tiop
->c_lflag
& TIO_ECHONL
)
if (tiop
->c_lflag
& TIO_ISIG
)
if (tiop
->c_lflag
& TIO_ICANON
)
tios
.c_lflag
|= (ICANON
|IEXTEN
);
if (tiop
->c_lflag
& TIO_NOFLSH
)
* No HP-UX equivs of VEOL2/VWERASE/VREPRINT/VSUSP/VDSUSP
* VSTOP/VLNEXT/VDISCARD/VMIN/VTIME/VSTATUS/VERASE2
tios
.c_cc
[VINTR
] = tiop
->c_cc
[HPUXVINTR
];
tios
.c_cc
[VQUIT
] = tiop
->c_cc
[HPUXVQUIT
];
tios
.c_cc
[VERASE
] = tiop
->c_cc
[HPUXVERASE
];
tios
.c_cc
[VKILL
] = tiop
->c_cc
[HPUXVKILL
];
if (tios
.c_lflag
& ICANON
) {
tios
.c_cc
[VEOF
] = tiop
->c_cc
[HPUXVEOF
];
tios
.c_cc
[VEOL
] = tiop
->c_cc
[HPUXVEOL
];
tios
.c_cc
[VMIN
] = tiop
->c_cc
[HPUXVMIN
];
tios
.c_cc
[VTIME
] = tiop
->c_cc
[HPUXVTIME
];
else if (com
== HPUXTCSETAW
)
error
= (*ioctlrout
)(fp
, com
, (caddr_t
)&tios
);
(void) (*ioctlrout
)(fp
, TIOCSETD
, (caddr_t
)&line
);
* Set non-blocking IO if VMIN == VTIME == 0.
* Should handle the other cases as well. It also
* isn't correct to just turn it off as it could be
* on as the result of a fcntl operation.
* XXX - wouldn't need to do this at all if VMIN/VTIME
line
= (tiop
->c_cc
[HPUXVMIN
] == 0 &&
tiop
->c_cc
[HPUXVTIME
] == 0);
(void) fset(fp
, FNDELAY
, line
);
case B50
: return(TIO_B50
);
case B75
: return(TIO_B75
);
case B110
: return(TIO_B110
);
case B134
: return(TIO_B134
);
case B150
: return(TIO_B150
);
case B200
: return(TIO_B200
);
case B300
: return(TIO_B300
);
case B600
: return(TIO_B600
);
case B1200
: return(TIO_B1200
);
case B1800
: return(TIO_B1800
);
case B2400
: return(TIO_B2400
);
case B4800
: return(TIO_B4800
);
case B9600
: return(TIO_B9600
);
case B19200
: return(TIO_B19200
);
case B38400
: return(TIO_B38400
);
static char hpuxtobsdbaudtab
[32] = {
B0
, B50
, B75
, B110
, B134
, B150
, B200
, B300
,
B600
, B0
, B1200
, B1800
, B2400
, B0
, B4800
, B0
,
B9600
, B19200
, B38400
, B0
, B0
, B0
, B0
, B0
,
B0
, B0
, B0
, B0
, B0
, B0
, EXTA
, EXTB
return(hpuxtobsdbaudtab
[hpuxspeed
& TIO_CBAUD
]);
ohpuxgtty(p
, uap
, retval
)
return (getsettty(p
, uap
->fdes
, HPUXTIOCGETP
, uap
->cmarg
));
ohpuxstty(p
, uap
, retval
)
return (getsettty(p
, uap
->fdes
, HPUXTIOCSETP
, uap
->cmarg
));
* Simplified version of ioctl() for use by
* gtty/stty and TIOCGETP/TIOCSETP.
getsettty(p
, fdes
, com
, cmarg
)
register struct filedesc
*fdp
= p
->p_fd
;
register struct file
*fp
;
if (((unsigned)fdes
) >= fdp
->fd_maxfiles
||
(fp
= OFILE(fdp
, fdes
)) == NULL
)
if ((fp
->f_flag
& (FREAD
|FWRITE
)) == 0)
if (com
== HPUXTIOCSETP
) {
if (error
= copyin(cmarg
, (caddr_t
)&hsb
, sizeof hsb
))
sb
.sg_ispeed
= hsb
.sg_ispeed
;
sb
.sg_ospeed
= hsb
.sg_ospeed
;
sb
.sg_erase
= hsb
.sg_erase
;
sb
.sg_kill
= hsb
.sg_kill
;
sb
.sg_flags
= hsb
.sg_flags
& ~(V7_HUPCL
|V7_XTABS
|V7_NOAL
);
if (hsb
.sg_flags
& V7_XTABS
)
if (hsb
.sg_flags
& V7_HUPCL
)
(void)(*fp
->f_ops
->fo_ioctl
)(fp
, TIOCHPCL
, (caddr_t
)0);
bzero((caddr_t
)&hsb
, sizeof hsb
);
error
= (*fp
->f_ops
->fo_ioctl
)(fp
, com
, (caddr_t
)&sb
);
if (error
== 0 && com
== TIOCGETP
) {
hsb
.sg_ispeed
= sb
.sg_ispeed
;
hsb
.sg_ospeed
= sb
.sg_ospeed
;
hsb
.sg_erase
= sb
.sg_erase
;
hsb
.sg_kill
= sb
.sg_kill
;
hsb
.sg_flags
= sb
.sg_flags
& ~(V7_HUPCL
|V7_XTABS
|V7_NOAL
);
hsb
.sg_flags
|= V7_XTABS
;
error
= copyout((caddr_t
)&hsb
, cmarg
, sizeof hsb
);