xterm_io.h revision 913cc679
1/* $XTermId: xterm_io.h,v 1.64 2017/05/18 21:15:14 tom Exp $ */
2
3/*
4 * Copyright 2000-2014,2017 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#if defined(__minix)
45#define USE_POSIX_TERMIOS 1
46#undef HAVE_POSIX_OPENPT	/* present, does not work */
47#endif
48
49#ifdef CSRG_BASED
50#define USE_TERMIOS
51#endif
52
53#ifdef __CYGWIN__
54#define ATT
55#define SVR4
56#define SYSV
57#define USE_SYSV_TERMIO
58#endif
59
60#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__INTERIX) || defined(__APPLE__) || defined(__UNIXWARE__) || defined(__hpux)
61#ifndef USE_POSIX_TERMIOS
62#define USE_POSIX_TERMIOS
63#endif
64#endif
65
66#if defined(AIXV4)
67#define USE_POSIX_TERMIOS
68#ifndef SYSV
69#define SYSV
70#endif
71#endif
72
73#ifdef linux
74#define USE_TERMIOS
75#endif
76
77#ifdef __SCO__
78#define USE_TERMIOS
79#ifndef _SVID3
80#define _SVID3
81#endif
82#endif
83
84#ifdef Lynx
85#define USE_SYSV_TERMIO
86#endif
87
88#ifdef macII
89#undef SYSV			/* pretend to be bsd (sgtty.h) */
90#endif /* macII */
91
92#if defined(__GLIBC__) && !defined(linux)
93#define USE_POSIX_TERMIOS	/* GNU/Hurd, GNU/KFreeBSD and GNU/KNetBSD */
94#endif
95
96#ifdef __MVS__
97#define SVR4
98#define USE_POSIX_TERMIOS
99#endif
100
101#ifdef __QNX__
102#define USE_POSIX_TERMIOS
103#endif
104
105#if defined(__osf__)
106#define USE_POSIX_TERMIOS
107#undef SYSV
108#endif
109
110/*
111 * Indirect system dependencies
112 */
113#if defined(SVR4) && !defined(__sgi)
114#define USE_TERMIOS
115#endif
116
117#ifdef SYSV
118#define USE_SYSV_TERMIO
119#endif
120
121#if defined(USE_POSIX_TERMIOS) && !defined(USE_TERMIOS)
122#define USE_TERMIOS
123#endif
124
125/*
126 * Low-level ioctl, where it is needed or non-conflicting with termio/etc.
127 */
128#ifdef __QNX__
129#include <ioctl.h>
130#else
131#include <sys/ioctl.h>
132#endif
133
134/*
135 * Terminal I/O includes (termio, termios, sgtty headers).
136 */
137#if defined(USE_POSIX_TERMIOS) && !defined(__hpux)
138#include <termios.h>
139#elif defined(USE_TERMIOS)
140#include <termios.h>
141/* this hacked termios support only works on SYSV */
142#define USE_ANY_SYSV_TERMIO
143#define termio termios
144#ifndef __CYGWIN__
145#undef  TCGETA
146#define TCGETA TCGETS
147#undef  TCSETA
148#define TCSETA TCSETS
149#undef  TCSETAW
150#define TCSETAW TCSETSW
151#endif
152#elif defined(USE_SYSV_TERMIO)
153# define USE_ANY_SYSV_TERMIO
154# ifdef Lynx
155#  include <termio.h>
156# else
157#  include <sys/termio.h>
158# endif
159#elif defined(SYSV) || defined(ISC)
160# include <sys/termio.h>
161#elif !defined(VMS)
162# include <sgtty.h>
163#endif /* USE_POSIX_TERMIOS */
164
165/*
166 * Stream includes, which declare struct winsize or ttysize.
167 */
168#ifdef SYSV
169#ifdef USE_USG_PTYS
170#include <sys/stream.h>		/* get typedef used in ptem.h */
171#ifdef HAVE_SYS_PTEM_H
172#include <sys/ptem.h>		/* get struct winsize */
173#endif
174#endif /* USE_USG_PTYS */
175#endif /* SYSV */
176
177/*
178 * Special cases (structures and definitions that have to be adjusted).
179 */
180#if defined(__CYGWIN__) && !defined(TIOCSPGRP)
181#include <termios.h>
182#define TIOCSPGRP (_IOW('t', 118, pid_t))
183#endif
184
185#ifdef __hpux
186#include <sys/bsdtty.h>		/* defines TIOCSLTC */
187#endif
188
189#ifdef ISC
190#define TIOCGPGRP TCGETPGRP
191#define TIOCSPGRP TCSETPGRP
192#endif
193
194#ifdef Lynx
195#include <resource.h>
196#elif !(defined(SYSV) || defined(linux) || defined(VMS) || (defined(__QNX__)&&!defined(__QNXNTO__)))
197#include <sys/resource.h>
198#endif
199
200#ifdef macII
201#undef FIOCLEX
202#undef FIONCLEX
203#endif /* macII */
204
205#if defined(__QNX__) || defined(__GNU__) || defined(__MVS__) || defined(__osf__)
206#undef TIOCSLTC			/* <sgtty.h> conflicts with <termios.h> */
207#undef TIOCSLTC
208#endif
209
210#if defined (__sgi) || (defined(__linux__) && defined(__sparc__)) || defined(__UNIXWARE__)
211#undef TIOCLSET			/* defined, but not useable */
212#endif
213
214#if defined(sun) || defined(__UNIXWARE__)
215#include <sys/filio.h>
216#endif
217
218#if defined(TIOCSLTC) && ! (defined(linux) || defined(__MVS__) || defined(Lynx) || defined(SVR4))
219#define HAS_LTCHARS
220#endif
221
222#if !defined(TTYSIZE_STRUCT)
223#if defined(TIOCSWINSZ)
224#define USE_STRUCT_WINSIZE 1
225#define TTYSIZE_STRUCT struct winsize
226#define GET_TTYSIZE(fd, data) ioctl(fd, TIOCGWINSZ, (char *) &data)
227#define SET_TTYSIZE(fd, data) ioctl(fd, TIOCSWINSZ, (char *) &data)
228#define TTYSIZE_COLS(data) data.ws_col
229#define TTYSIZE_ROWS(data) data.ws_row
230#endif /* TIOCSWINSZ */
231#endif /* TTYSIZE_STRUCT */
232
233#ifndef USE_STRUCT_WINSIZE
234#error "There is a configuration error with struct winsize ifdef"
235#endif
236
237/* "resize" depends upon order of assignments in this macro */
238#ifdef USE_STRUCT_WINSIZE
239#define setup_winsize(ts, rows, cols, height, width) \
240    (ts).ws_xpixel = (ttySize_t) (width), \
241    (ts).ws_ypixel = (ttySize_t) (height), \
242    TTYSIZE_ROWS(ts) = (ttySize_t) (rows), \
243    TTYSIZE_COLS(ts) = (ttySize_t) (cols)
244#else
245#define setup_winsize(ts, rows, cols, height, width) \
246    TTYSIZE_ROWS(ts) = (ttySize_t) (rows), \
247    TTYSIZE_COLS(ts) = (ttySize_t) (cols)
248#endif
249
250#if OPT_TRACE
251
252#ifdef USE_STRUCT_WINSIZE
253#define trace_winsize(ts, id) \
254    TRACE(("%s@%d, TTYSIZE %s chars %dx%d pixels %dx%d\n", \
255    	   __FILE__, __LINE__, id, \
256	   TTYSIZE_ROWS(ts), TTYSIZE_COLS(ts), (ts).ws_ypixel, (ts).ws_xpixel))
257#else
258#define trace_winsize(ts, id) \
259    TRACE(("%s@%d, TTYSIZE %s chars %dx%d\n", __FILE__, __LINE__, id, \
260    	   TTYSIZE_ROWS(ts), TTYSIZE_COLS(ts)))
261#endif
262
263#define TRACE_GET_TTYSIZE(fd, id) { \
264	    TTYSIZE_STRUCT debug_ttysize; \
265	    if (GET_TTYSIZE(fd, debug_ttysize) == 0) \
266		trace_winsize(debug_ttysize, id); \
267	    else \
268		TRACE(("%s@%d, TTYSIZE failed %s\n", __FILE__, __LINE__, strerror(errno))); \
269	}
270#else
271#define trace_winsize(ts, id)	/* nothing */
272#define TRACE_GET_TTYSIZE(fd, id)	/* nothing */
273#endif
274
275typedef unsigned short ttySize_t;
276
277#endif /* included_xterm_io_h */
278