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