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