initial commit
[profile/ivi/xterm.git] / xterm_io.h
1 /* $XTermId: xterm_io.h,v 1.50 2010/05/23 16:04:32 tom Exp $ */
2
3 /*
4  * Copyright 2000-2006,2010 by Thomas E. Dickey
5  *
6  *                         All Rights Reserved
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the
10  * "Software"), to deal in the Software without restriction, including
11  * without limitation the rights to use, copy, modify, merge, publish,
12  * distribute, sublicense, and/or sell copies of the Software, and to
13  * permit persons to whom the Software is furnished to do so, subject to
14  * the following conditions:
15  *
16  * The above copyright notice and this permission notice shall be included
17  * in all copies or substantial portions of the Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
22  * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
23  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26  *
27  * Except as contained in this notice, the name(s) of the above copyright
28  * holders shall not be used in advertising or otherwise to promote the
29  * sale, use or other dealings in this Software without prior written
30  * authorization.
31  */
32
33 #ifndef included_xterm_io_h
34 #define included_xterm_io_h
35
36 #include <xterm.h>
37
38 /*
39  * System-specific definitions (keep these chunks one-per-system!).
40  *
41  * FIXME:  some, such as those defining USE_TERMIOS should be moved to xterm.h
42  * as they are integrated with the configure script.
43  */
44 #ifdef CSRG_BASED
45 #define USE_TERMIOS
46 #endif
47
48 #ifdef __CYGWIN__
49 #define ATT
50 #define SVR4
51 #define SYSV
52 #define USE_SYSV_TERMIO
53 #endif
54
55 #ifdef __UNIXOS2__
56 #define USE_SYSV_TERMIO
57 #endif
58
59 #if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__INTERIX) || defined(__APPLE__) || defined(__UNIXWARE__)
60 #ifndef USE_POSIX_TERMIOS
61 #define USE_POSIX_TERMIOS
62 #endif
63 #endif
64
65 #if defined(AIXV4)
66 #define USE_POSIX_TERMIOS
67 #ifndef SYSV
68 #define SYSV
69 #endif
70 #endif
71
72 #ifdef linux
73 #define USE_TERMIOS
74 #endif
75
76 #ifdef __SCO__
77 #define USE_TERMIOS
78 #ifndef _SVID3
79 #define _SVID3
80 #endif
81 #endif
82
83 #ifdef Lynx
84 #define USE_SYSV_TERMIO
85 #endif
86
87 #ifdef macII
88 #undef SYSV                     /* pretend to be bsd (sgtty.h) */
89 #endif /* macII */
90
91 #if defined(__GLIBC__) && !defined(linux)
92 #define USE_POSIX_TERMIOS       /* GNU/Hurd, GNU/KFreeBSD and GNU/KNetBSD */
93 #endif
94
95 #ifdef __MVS__
96 #define SVR4
97 #define USE_POSIX_TERMIOS
98 #endif
99
100 #ifdef __QNX__
101 #define USE_POSIX_TERMIOS
102 #endif
103
104 #if defined(__osf__)
105 #define USE_POSIX_TERMIOS
106 #undef SYSV
107 #endif
108
109 /*
110  * Indirect system dependencies
111  */
112 #if defined(SVR4) && !defined(__sgi)
113 #define USE_TERMIOS
114 #endif
115
116 #ifdef SYSV
117 #define USE_SYSV_TERMIO
118 #endif
119
120 #if defined(USE_POSIX_TERMIOS) && !defined(USE_TERMIOS)
121 #define USE_TERMIOS
122 #endif
123
124 /*
125  * Low-level ioctl, where it is needed or non-conflicting with termio/etc.
126  */
127 #ifdef __QNX__
128 #include <ioctl.h>
129 #else
130 #include <sys/ioctl.h>
131 #endif
132
133 /*
134  * Terminal I/O includes (termio, termios, sgtty headers).
135  */
136 #if defined(USE_POSIX_TERMIOS)
137 #include <termios.h>
138 #elif defined(USE_TERMIOS)
139 #include <termios.h>
140 /* this hacked termios support only works on SYSV */
141 #define USE_ANY_SYSV_TERMIO
142 #define termio termios
143 #ifndef __CYGWIN__
144 #undef  TCGETA
145 #define TCGETA TCGETS
146 #undef  TCSETA
147 #define TCSETA TCSETS
148 #undef  TCSETAW
149 #define TCSETAW TCSETSW
150 #endif
151 #elif defined(USE_SYSV_TERMIO)
152 # define USE_ANY_SYSV_TERMIO
153 # ifdef Lynx
154 #  include <termio.h>
155 # else
156 #  include <sys/termio.h>
157 # endif
158 #elif defined(SYSV) || defined(ISC)
159 # include <sys/termio.h>
160 #elif !defined(VMS)
161 # include <sgtty.h>
162 #endif /* USE_POSIX_TERMIOS */
163
164 /*
165  * Stream includes, which declare struct winsize or ttysize.
166  */
167 #ifdef SYSV
168 #ifdef USE_USG_PTYS
169 #include <sys/stream.h>                 /* get typedef used in ptem.h */
170 #if !defined(SVR4) || defined(__SCO__)
171 #include <sys/ptem.h>                   /* get struct winsize */
172 #endif
173 #endif /* USE_USG_PTYS */
174 #elif defined(sun) && !defined(SVR4)
175 #include <sys/ttycom.h>
176 #ifdef TIOCSWINSZ
177 #undef TIOCSSIZE
178 #endif
179 #endif /* SYSV */
180
181 /*
182  * Special cases (structures and definitions that have to be adjusted).
183  */
184 #if defined(__CYGWIN__) && !defined(TIOCSPGRP)
185 #include <termios.h>
186 #define TIOCSPGRP (_IOW('t', 118, pid_t))
187 #endif
188
189 #ifdef __UNIXOS2__
190
191 #define XFREE86_PTY     0x76
192
193 #define XTY_TIOCSETA    0x48
194 #define XTY_TIOCSETAW   0x49
195 #define XTY_TIOCSETAF   0x4a
196 #define XTY_TIOCCONS    0x4d
197 #define XTY_TIOCSWINSZ  0x53
198 #define XTY_ENADUP      0x5a
199 #define XTY_TRACE       0x5b
200 #define XTY_TIOCGETA    0x65
201 #define XTY_TIOCGWINSZ  0x66
202 #define PTMS_GETPTY     0x64
203 #define PTMS_BUFSZ      14
204
205 #ifndef NCCS
206 #define NCCS 11
207 #endif
208
209 #define TIOCCONS        108
210 #define TIOCSWINSZ      113
211 #define TIOCGWINSZ      117
212
213 struct pt_termios
214 {
215         unsigned short  c_iflag;
216         unsigned short  c_oflag;
217         unsigned short  c_cflag;
218         unsigned short  c_lflag;
219         unsigned char   c_cc[NCCS];
220         long            _reserved_[4];
221 };
222
223 struct winsize {
224         unsigned short  ws_row;         /* rows, in characters */
225         unsigned short  ws_col;         /* columns, in characters */
226         unsigned short  ws_xpixel;      /* horizontal size, pixels */
227         unsigned short  ws_ypixel;      /* vertical size, pixels */
228 };
229 #define TTYSIZE_STRUCT struct winsize
230 #define USE_STRUCT_WINSIZE 1
231
232 #ifdef XTERM_MAIN
233 extern int ptioctl(int fd, int func, void* data);
234 #define ioctl ptioctl
235 #endif
236
237 #endif /* __UNIXOS2__ */
238
239 #ifdef __hpux
240 #include <sys/bsdtty.h>         /* defines TIOCSLTC */
241 #endif
242
243 #ifdef ISC
244 #define TIOCGPGRP TCGETPGRP
245 #define TIOCSPGRP TCSETPGRP
246 #endif
247
248 #ifdef Lynx
249 #include <resource.h>
250 #elif !(defined(SYSV) || defined(linux) || defined(VMS) || (defined(__QNX__)&&!defined(__QNXNTO__)))
251 #include <sys/resource.h>
252 #endif
253
254 #ifdef macII
255 #undef FIOCLEX
256 #undef FIONCLEX
257 #endif /* macII */
258
259 #ifdef __QNX__
260 #undef TIOCSLTC                 /* <sgtty.h> conflicts with <termios.h> */
261 #undef TIOCLSET
262 #endif
263
264 #if defined(__sgi) && (OSMAJORVERSION >= 5)
265 #undef TIOCLSET                         /* defined, but not useable */
266 #endif
267
268 #if defined(__GNU__) || defined(__MVS__) || defined(__osf__)
269 #undef TIOCLSET
270 #undef TIOCSLTC
271 #endif
272
273 #if defined (__sgi) || (defined(__linux__) && defined(__sparc__)) || defined(__UNIXWARE__)
274 #undef TIOCLSET /* XXX why is this undef-ed again? */
275 #endif
276
277 #if defined(sun) || defined(__UNIXWARE__)
278 #include <sys/filio.h>
279 #endif
280
281 #if defined(TIOCSLTC) && ! (defined(linux) || defined(__MVS__) || defined(Lynx) || defined(SVR4))
282 #define HAS_LTCHARS
283 #endif
284
285 #if !defined(TTYSIZE_STRUCT)
286 #if defined(TIOCSSIZE) && (defined(sun) && !defined(SVR4))
287 #define USE_STRUCT_TTYSIZE 1
288 #define TTYSIZE_STRUCT struct ttysize
289 #elif defined(TIOCSWINSZ)
290 #define USE_STRUCT_WINSIZE 1
291 #define TTYSIZE_STRUCT struct winsize
292 #endif /* sun vs TIOCSWINSZ */
293 #endif /* TTYSIZE_STRUCT */
294
295 #if defined(USE_STRUCT_TTYSIZE)
296 #define TTYSIZE_STRUCT struct ttysize
297 #define SET_TTYSIZE(fd, data) ioctl(fd, TIOCSSIZE, &data);
298 #define TTYSIZE_COLS(data) data.ts_cols
299 #define TTYSIZE_ROWS(data) data.ts_lines
300 #elif defined(USE_STRUCT_WINSIZE)
301 #define TTYSIZE_STRUCT struct winsize
302 #define SET_TTYSIZE(fd, data) ioctl(fd, TIOCSWINSZ, (char *) &data)
303 #define TTYSIZE_COLS(data) data.ws_col
304 #define TTYSIZE_ROWS(data) data.ws_row
305 #endif
306
307 typedef unsigned short ttySize_t;
308
309 #endif  /* included_xterm_io_h */