1*4887Schin /*********************************************************************** 2*4887Schin * * 3*4887Schin * This software is part of the ast package * 4*4887Schin * Copyright (c) 1982-2007 AT&T Knowledge Ventures * 5*4887Schin * and is licensed under the * 6*4887Schin * Common Public License, Version 1.0 * 7*4887Schin * by AT&T Knowledge Ventures * 8*4887Schin * * 9*4887Schin * A copy of the License is available at * 10*4887Schin * http://www.opensource.org/licenses/cpl1.0.txt * 11*4887Schin * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) * 12*4887Schin * * 13*4887Schin * Information and Software Systems Research * 14*4887Schin * AT&T Research * 15*4887Schin * Florham Park NJ * 16*4887Schin * * 17*4887Schin * David Korn <dgk@research.att.com> * 18*4887Schin * * 19*4887Schin ***********************************************************************/ 20*4887Schin #pragma prototyped 21*4887Schin 22*4887Schin #ifndef _terminal_ 23*4887Schin #define _terminal_ 1 24*4887Schin 25*4887Schin #include "FEATURE/ttys" 26*4887Schin /* 27*4887Schin * terminal interface 28*4887Schin * complicated by the fact that there are so many variations 29*4887Schin * This will use POSIX <termios.h> interface where available 30*4887Schin */ 31*4887Schin 32*4887Schin #ifdef _hdr_termios 33*4887Schin # include <termios.h> 34*4887Schin # if __sgi__ || sgi /* special hack to eliminate ^M problem */ 35*4887Schin # ifndef ECHOCTL 36*4887Schin # define ECHOCTL ECHOE 37*4887Schin # endif /* ECHOCTL */ 38*4887Schin # ifndef CNSUSP 39*4887Schin # define CNSUSP CNSWTCH 40*4887Schin # endif /* CNSUSP */ 41*4887Schin # endif /* sgi */ 42*4887Schin # ifdef _NEXT_SOURCE 43*4887Schin # define _lib_tcgetattr 1 44*4887Schin # define _lib_tcgetpgrp 1 45*4887Schin # endif /* _NEXT_SOURCE */ 46*4887Schin #else 47*4887Schin # if defined(_sys_termios) && defined(_lib_tcgetattr) 48*4887Schin # include <sys/termios.h> 49*4887Schin # define _hdr_termios 50*4887Schin # else 51*4887Schin # undef _sys_termios 52*4887Schin # endif /* _sys_termios */ 53*4887Schin #endif /* _hdr_termios */ 54*4887Schin 55*4887Schin #ifdef _hdr_termios 56*4887Schin # undef _hdr_sgtty 57*4887Schin # undef tcgetattr 58*4887Schin # undef tcsetattr 59*4887Schin # undef tcgetpgrp 60*4887Schin # undef tcsetpgrp 61*4887Schin # undef cfgetospeed 62*4887Schin # ifndef TCSANOW 63*4887Schin # define TCSANOW TCSETS 64*4887Schin # define TCSADRAIN TCSETSW 65*4887Schin # define TCSAFLUSH TCSETSF 66*4887Schin # endif /* TCSANOW */ 67*4887Schin /* The following corrects bugs in some implementations */ 68*4887Schin # if defined(TCSADFLUSH) && !defined(TCSAFLUSH) 69*4887Schin # define TCSAFLUSH TCSADFLUSH 70*4887Schin # endif /* TCSADFLUSH */ 71*4887Schin # ifndef _lib_tcgetattr 72*4887Schin # undef tcgetattr 73*4887Schin # define tcgetattr(fd,tty) ioctl(fd, TCGETS, tty) 74*4887Schin # undef tcsetattr 75*4887Schin # define tcsetattr(fd,action,tty) ioctl(fd, action, tty) 76*4887Schin # undef cfgetospeed 77*4887Schin # define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) 78*4887Schin # endif /* _lib_tcgetattr */ 79*4887Schin # undef TIOCGETC 80*4887Schin # if SHOPT_OLDTERMIO /* use both termios and termio */ 81*4887Schin # ifdef _hdr_termio 82*4887Schin # include <termio.h> 83*4887Schin # else 84*4887Schin # ifdef _sys_termio 85*4887Schin # include <sys/termio.h> 86*4887Schin # define _hdr_termio 1 87*4887Schin # else 88*4887Schin # undef SHOPT_OLDTERMIO 89*4887Schin # endif /* _sys_termio */ 90*4887Schin # endif /* _hdr_termio */ 91*4887Schin # endif /* SHOPT_OLDTERMIO */ 92*4887Schin #else 93*4887Schin # define cfgetospeed(tp) ((tp)->c_cflag & CBAUD) 94*4887Schin # undef SHOPT_OLDTERMIO 95*4887Schin # ifdef _hdr_termio 96*4887Schin # include <termio.h> 97*4887Schin # else 98*4887Schin # ifdef _sys_termio 99*4887Schin # include <sys/termio.h> 100*4887Schin # define _hdr_termio 1 101*4887Schin # endif /* _sys_termio */ 102*4887Schin # endif /* _hdr_termio */ 103*4887Schin # ifdef _hdr_termio 104*4887Schin # define termios termio 105*4887Schin # undef TIOCGETC 106*4887Schin # define tcgetattr(fd,tty) ioctl(fd, TCGETA, tty) 107*4887Schin # define tcsetattr(fd,action,tty) ioctl(fd, action, tty) 108*4887Schin 109*4887Schin # ifdef _sys_bsdtty 110*4887Schin # include <sys/bsdtty.h> 111*4887Schin # endif /* _sys_bsdtty */ 112*4887Schin # else 113*4887Schin # ifdef _hdr_sgtty 114*4887Schin # include <sgtty.h> 115*4887Schin # ifndef LPENDIN 116*4887Schin # ifdef _sys_nttyio 117*4887Schin # include <sys/nttyio.h> 118*4887Schin # endif /* _sys_nttyio */ 119*4887Schin # endif /* LPENDIN */ 120*4887Schin # define termios sgttyb 121*4887Schin # ifdef TIOCSETN 122*4887Schin # undef TCSETAW 123*4887Schin # endif /* TIOCSETN */ 124*4887Schin # ifdef TIOCGETP 125*4887Schin # define tcgetattr(fd,tty) ioctl(fd, TIOCGETP, tty) 126*4887Schin # define tcsetattr(fd,action,tty) ioctl(fd, action, tty) 127*4887Schin # else 128*4887Schin # define tcgetattr(fd,tty) gtty(fd, tty) 129*4887Schin # define tcsetattr(fd,action,tty) stty(fd, tty) 130*4887Schin # endif /* TIOCGETP */ 131*4887Schin # endif /* _hdr_sgtty */ 132*4887Schin # endif /* hdr_termio */ 133*4887Schin 134*4887Schin # ifndef TCSANOW 135*4887Schin # ifdef TCSETAW 136*4887Schin # define TCSANOW TCSETA 137*4887Schin # ifdef u370 138*4887Schin /* delays are too long, don't wait for output to drain */ 139*4887Schin # define TCSADRAIN TCSETA 140*4887Schin # else 141*4887Schin # define TCSADRAIN TCSETAW 142*4887Schin # endif /* u370 */ 143*4887Schin # define TCSAFLUSH TCSETAF 144*4887Schin # else 145*4887Schin # ifdef TIOCSETN 146*4887Schin # define TCSANOW TIOCSETN 147*4887Schin # define TCSADRAIN TIOCSETN 148*4887Schin # define TCSAFLUSH TIOCSETP 149*4887Schin # endif /* TIOCSETN */ 150*4887Schin # endif /* TCSETAW */ 151*4887Schin # endif /* TCSANOW */ 152*4887Schin #endif /* _hdr_termios */ 153*4887Schin 154*4887Schin /* set ECHOCTL if driver can echo control charaters as ^c */ 155*4887Schin #ifdef LCTLECH 156*4887Schin # ifndef ECHOCTL 157*4887Schin # define ECHOCTL LCTLECH 158*4887Schin # endif /* !ECHOCTL */ 159*4887Schin #endif /* LCTLECH */ 160*4887Schin #ifdef LNEW_CTLECH 161*4887Schin # ifndef ECHOCTL 162*4887Schin # define ECHOCTL LNEW_CTLECH 163*4887Schin # endif /* !ECHOCTL */ 164*4887Schin #endif /* LNEW_CTLECH */ 165*4887Schin #ifdef LNEW_PENDIN 166*4887Schin # ifndef PENDIN 167*4887Schin # define PENDIN LNEW_PENDIN 168*4887Schin # endif /* !PENDIN */ 169*4887Schin #endif /* LNEW_PENDIN */ 170*4887Schin #ifndef ECHOCTL 171*4887Schin # ifndef VEOL 172*4887Schin # define RAWONLY 1 173*4887Schin # endif /* !VEOL */ 174*4887Schin #endif /* !ECHOCTL */ 175*4887Schin 176*4887Schin #ifdef _sys_filio 177*4887Schin # ifndef FIONREAD 178*4887Schin # include <sys/filio.h> 179*4887Schin # endif /* FIONREAD */ 180*4887Schin #endif /* _sys_filio */ 181*4887Schin /* set FIORDCHK if you can check for characters in input queue */ 182*4887Schin #ifdef FIONREAD 183*4887Schin # ifndef FIORDCHK 184*4887Schin # define FIORDCHK FIONREAD 185*4887Schin # endif /* !FIORDCHK */ 186*4887Schin #endif /* FIONREAD */ 187*4887Schin 188*4887Schin extern int tty_alt(int); 189*4887Schin extern void tty_cooked(int); 190*4887Schin extern int tty_get(int,struct termios*); 191*4887Schin extern int tty_raw(int,int); 192*4887Schin extern int tty_check(int); 193*4887Schin extern int tty_set(int, int, struct termios*); 194*4887Schin 195*4887Schin #endif /* _terminal_ */ 196