xref: /onnv-gate/usr/src/lib/libshell/common/include/terminal.h (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1982-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                  David Korn <dgk@research.att.com>                   *
184887Schin *                                                                      *
194887Schin ***********************************************************************/
204887Schin #pragma prototyped
214887Schin 
224887Schin #ifndef _terminal_
234887Schin #define _terminal_	1
244887Schin 
254887Schin #include	"FEATURE/ttys"
264887Schin /*
274887Schin  * terminal interface
284887Schin  * complicated by the fact that there are so many variations
294887Schin  * This will use POSIX <termios.h> interface where available
304887Schin  */
314887Schin 
324887Schin #ifdef _hdr_termios
334887Schin #   include	<termios.h>
344887Schin #   if __sgi__ || sgi	/* special hack to eliminate ^M problem */
354887Schin #	ifndef ECHOCTL
364887Schin #	    define ECHOCTL	ECHOE
374887Schin #	endif /* ECHOCTL */
384887Schin #	ifndef CNSUSP
394887Schin #	    define CNSUSP	CNSWTCH
404887Schin #	endif /* CNSUSP */
414887Schin #   endif /* sgi */
424887Schin #   ifdef _NEXT_SOURCE
434887Schin #	define _lib_tcgetattr	1
444887Schin #	define _lib_tcgetpgrp	1
454887Schin #   endif /* _NEXT_SOURCE */
464887Schin #else
474887Schin #   if defined(_sys_termios) && defined(_lib_tcgetattr)
484887Schin #	include	<sys/termios.h>
494887Schin #	define _hdr_termios
504887Schin #   else
514887Schin #	undef _sys_termios
524887Schin #   endif /* _sys_termios */
534887Schin #endif /* _hdr_termios */
544887Schin 
554887Schin #ifdef _hdr_termios
564887Schin #   undef _hdr_sgtty
574887Schin #   undef tcgetattr
584887Schin #   undef tcsetattr
594887Schin #   undef tcgetpgrp
604887Schin #   undef tcsetpgrp
614887Schin #   undef cfgetospeed
624887Schin #   ifndef TCSANOW
634887Schin #	define TCSANOW		TCSETS
644887Schin #	define TCSADRAIN	TCSETSW
654887Schin #	define TCSAFLUSH	TCSETSF
664887Schin #   endif /* TCSANOW */
674887Schin     /* The following corrects bugs in some implementations */
684887Schin #   if defined(TCSADFLUSH) && !defined(TCSAFLUSH)
694887Schin #	define TCSAFLUSH	TCSADFLUSH
704887Schin #   endif /* TCSADFLUSH */
714887Schin #   ifndef _lib_tcgetattr
724887Schin #	undef  tcgetattr
734887Schin #	define tcgetattr(fd,tty)	ioctl(fd, TCGETS, tty)
744887Schin #	undef  tcsetattr
754887Schin #	define tcsetattr(fd,action,tty)	ioctl(fd, action, tty)
764887Schin #	undef  cfgetospeed
774887Schin #	define cfgetospeed(tp)		((tp)->c_cflag & CBAUD)
784887Schin #   endif /* _lib_tcgetattr */
794887Schin #   undef TIOCGETC
804887Schin #   if SHOPT_OLDTERMIO  /* use both termios and termio */
814887Schin #	ifdef _hdr_termio
824887Schin #	    include	<termio.h>
834887Schin #	else
844887Schin #	    ifdef _sys_termio
854887Schin #		include	<sys/termio.h>
864887Schin #		define _hdr_termio 1
874887Schin #	    else
884887Schin #		undef SHOPT_OLDTERMIO
894887Schin #	    endif /* _sys_termio */
904887Schin #	endif /* _hdr_termio */
914887Schin #   endif /* SHOPT_OLDTERMIO */
924887Schin #else
934887Schin #   define cfgetospeed(tp)	((tp)->c_cflag & CBAUD)
944887Schin #   undef SHOPT_OLDTERMIO
954887Schin #   ifdef _hdr_termio
964887Schin #	include	<termio.h>
974887Schin #   else
984887Schin #	ifdef _sys_termio
994887Schin #	    include	<sys/termio.h>
1004887Schin #	    define _hdr_termio 1
1014887Schin #	endif /* _sys_termio */
1024887Schin #   endif /* _hdr_termio */
1034887Schin #   ifdef _hdr_termio
1044887Schin #	define termios termio
1054887Schin #	undef TIOCGETC
1064887Schin #	define tcgetattr(fd,tty)		ioctl(fd, TCGETA, tty)
1074887Schin #	define tcsetattr(fd,action,tty)	ioctl(fd, action, tty)
1084887Schin 
1094887Schin #	ifdef _sys_bsdtty
1104887Schin #	   include	<sys/bsdtty.h>
1114887Schin #	endif /* _sys_bsdtty */
1124887Schin #   else
1134887Schin #	ifdef _hdr_sgtty
1144887Schin #	    include	<sgtty.h>
1154887Schin #	    ifndef LPENDIN
1164887Schin #	        ifdef _sys_nttyio
1174887Schin #		    include	<sys/nttyio.h>
1184887Schin #	        endif /* _sys_nttyio */
1194887Schin #	    endif /* LPENDIN */
1204887Schin #	    define termios sgttyb
1214887Schin #	    ifdef TIOCSETN
1224887Schin #	 	undef TCSETAW
1234887Schin #	    endif /* TIOCSETN */
1244887Schin #	    ifdef TIOCGETP
1254887Schin #		define tcgetattr(fd,tty)		ioctl(fd, TIOCGETP, tty)
1264887Schin #		define tcsetattr(fd,action,tty)	ioctl(fd, action, tty)
1274887Schin #	    else
1284887Schin #		define tcgetattr(fd,tty)	gtty(fd, tty)
1294887Schin #		define tcsetattr(fd,action,tty)	stty(fd, tty)
1304887Schin #	    endif /* TIOCGETP */
1314887Schin #	endif /* _hdr_sgtty */
1324887Schin #   endif /* hdr_termio */
1334887Schin 
1344887Schin #   ifndef TCSANOW
1354887Schin #	ifdef TCSETAW
1364887Schin #	    define TCSANOW	TCSETA
1374887Schin #	    ifdef u370
1384887Schin 	    /* delays are too long, don't wait for output to drain */
1394887Schin #		define TCSADRAIN	TCSETA
1404887Schin #	    else
1414887Schin #		define TCSADRAIN	TCSETAW
1424887Schin #	    endif /* u370 */
1434887Schin #	    define TCSAFLUSH	TCSETAF
1444887Schin #	else
1454887Schin #	    ifdef TIOCSETN
1464887Schin #		define TCSANOW	TIOCSETN
1474887Schin #		define TCSADRAIN	TIOCSETN
1484887Schin #		define TCSAFLUSH	TIOCSETP
1494887Schin #	    endif /* TIOCSETN */
1504887Schin #	endif /* TCSETAW */
1514887Schin #   endif /* TCSANOW */
1524887Schin #endif /* _hdr_termios */
1534887Schin 
1544887Schin /* set ECHOCTL if driver can echo control charaters as ^c */
1554887Schin #ifdef LCTLECH
1564887Schin #   ifndef ECHOCTL
1574887Schin #	define ECHOCTL	LCTLECH
1584887Schin #   endif /* !ECHOCTL */
1594887Schin #endif /* LCTLECH */
1604887Schin #ifdef LNEW_CTLECH
1614887Schin #   ifndef ECHOCTL
1624887Schin #	define ECHOCTL  LNEW_CTLECH
1634887Schin #   endif /* !ECHOCTL */
1644887Schin #endif /* LNEW_CTLECH */
1654887Schin #ifdef LNEW_PENDIN
1664887Schin #   ifndef PENDIN
1674887Schin #	define PENDIN LNEW_PENDIN
1684887Schin #  endif /* !PENDIN */
1694887Schin #endif /* LNEW_PENDIN */
1704887Schin #ifndef ECHOCTL
1714887Schin #   ifndef VEOL
1724887Schin #	define RAWONLY	1
1734887Schin #   endif /* !VEOL */
1744887Schin #endif /* !ECHOCTL */
1754887Schin 
1764887Schin #ifdef _sys_filio
1774887Schin #   ifndef FIONREAD
1784887Schin #	include	<sys/filio.h>
1794887Schin #   endif /* FIONREAD */
1804887Schin #endif /* _sys_filio */
1814887Schin /* set FIORDCHK if you can check for characters in input queue */
1824887Schin #ifdef FIONREAD
1834887Schin #   ifndef FIORDCHK
1844887Schin #	define FIORDCHK	FIONREAD
1854887Schin #   endif /* !FIORDCHK */
1864887Schin #endif /* FIONREAD */
1874887Schin 
1884887Schin extern int	tty_alt(int);
1894887Schin extern void	tty_cooked(int);
1904887Schin extern int	tty_get(int,struct termios*);
1914887Schin extern int	tty_raw(int,int);
1924887Schin extern int	tty_check(int);
1934887Schin extern int	tty_set(int, int, struct termios*);
1944887Schin 
1954887Schin #endif /* _terminal_ */
196