xterm_io.h revision 04b94745
11.95Sdrochner/* $XTermId: xterm_io.h,v 1.69 2024/05/03 23:32:26 tom Exp $ */ 21.9Smycroft 31.9Smycroft/* 41.66Sad * Copyright 2000-2023,2024 by Thomas E. Dickey 51.9Smycroft * 61.9Smycroft * All Rights Reserved 71.9Smycroft * 81.58Sad * Permission is hereby granted, free of charge, to any person obtaining a 91.9Smycroft * copy of this software and associated documentation files (the 101.9Smycroft * "Software"), to deal in the Software without restriction, including 111.9Smycroft * without limitation the rights to use, copy, modify, merge, publish, 121.9Smycroft * distribute, sublicense, and/or sell copies of the Software, and to 131.9Smycroft * permit persons to whom the Software is furnished to do so, subject to 141.9Smycroft * the following conditions: 151.9Smycroft * 161.9Smycroft * The above copyright notice and this permission notice shall be included 171.9Smycroft * in all copies or substantial portions of the Software. 181.9Smycroft * 191.9Smycroft * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 201.9Smycroft * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 211.9Smycroft * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 221.9Smycroft * IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 231.9Smycroft * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 241.9Smycroft * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 251.9Smycroft * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 261.9Smycroft * 271.9Smycroft * Except as contained in this notice, the name(s) of the above copyright 281.9Smycroft * holders shall not be used in advertising or otherwise to promote the 291.9Smycroft * sale, use or other dealings in this Software without prior written 301.9Smycroft * authorization. 311.1Smycroft */ 321.1Smycroft 331.1Smycroft#ifndef included_xterm_io_h 341.1Smycroft#define included_xterm_io_h 351.1Smycroft 361.1Smycroft#include <xterm.h> 371.1Smycroft 381.1Smycroft/* 391.1Smycroft * System-specific definitions (keep these chunks one-per-system!). 401.1Smycroft * 411.1Smycroft * FIXME: some, such as those defining USE_TERMIOS should be moved to xterm.h 421.1Smycroft * as they are integrated with the configure script. 431.1Smycroft */ 441.1Smycroft#if defined(__minix) 451.1Smycroft#define USE_POSIX_TERMIOS 1 461.1Smycroft#undef HAVE_POSIX_OPENPT /* present, does not work */ 471.76Stsutsui#endif 481.1Smycroft 491.1Smycroft#ifdef CSRG_BASED 501.1Smycroft#define USE_TERMIOS 511.1Smycroft#endif 521.1Smycroft 531.1Smycroft#ifdef __CYGWIN__ 541.1Smycroft#define ATT 551.1Smycroft#define SVR4 561.1Smycroft#define SYSV 571.1Smycroft#define USE_SYSV_TERMIO 581.1Smycroft#endif 591.1Smycroft 601.1Smycroft#if defined(__DragonFly__) || defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__INTERIX) || defined(__APPLE__) || defined(__UNIXWARE__) || defined(__hpux) 611.1Smycroft#ifndef USE_POSIX_TERMIOS 621.1Smycroft#define USE_POSIX_TERMIOS 631.1Smycroft#endif 641.1Smycroft#endif 651.1Smycroft 661.29Sjdolecek#if defined(AIXV4) 671.8Sthorpej#define USE_POSIX_TERMIOS 681.8Sthorpej#ifndef SYSV 691.8Sthorpej#define SYSV 701.41Schristos#endif 711.61Sbouyer#endif 721.22Sjdolecek 731.7Sthorpej#ifdef __linux__ 741.47Sad#define USE_TERMIOS 751.47Sad#define HAVE_POSIX_OPENPT 1 761.47Sad#define HAVE_PTSNAME 1 771.1Smycroft#define HAVE_GRANTPT_PTY_ISATTY 1 781.1Smycroft#endif 791.1Smycroft 801.1Smycroft#ifdef __SCO__ 811.1Smycroft#define USE_TERMIOS 821.47Sad#ifndef _SVID3 831.47Sad#define _SVID3 841.79Sad#endif 851.47Sad#endif 861.25Sfvdl 871.25Sfvdl#ifdef Lynx 881.25Sfvdl#define USE_SYSV_TERMIO 891.27Ssommerfe#endif 901.25Sfvdl 911.1Smycroft#ifdef macII 921.18Sthorpej#undef SYSV /* pretend to be bsd (sgtty.h) */ 931.6Smrg#endif /* macII */ 941.1Smycroft 951.1Smycroft#ifdef __GNU__ 961.1Smycroft#define USE_POSIX_TERMIOS 971.33Sfvdl#define HAVE_POSIX_OPENPT 1 981.33Sfvdl#define HAVE_PTSNAME 1 991.55Sad#define HAVE_GRANTPT_PTY_ISATTY 1 1001.1Smycroft#endif 1011.61Sbouyer 1021.91Scegger#if defined(__GLIBC__) && !(defined(__linux__) || defined(__GNU__)) 1031.61Sbouyer#define USE_POSIX_TERMIOS /* GNU/KFreeBSD and GNU/KNetBSD */ 1041.61Sbouyer#endif 1051.80Spooka 1061.33Sfvdl#ifdef __MVS__ 1071.61Sbouyer#define SVR4 1081.1Smycroft#define USE_POSIX_TERMIOS 1091.41Schristos#endif 1101.41Schristos 1111.1Smycroft#ifdef __QNX__ 1121.1Smycroft#define USE_POSIX_TERMIOS 1131.1Smycroft#endif 1141.1Smycroft 1151.1Smycroft#if defined(__osf__) 1161.13Sfvdl#define USE_POSIX_TERMIOS 1171.13Sfvdl#undef SYSV 1181.1Smycroft#endif 1191.1Smycroft 1201.1Smycroft/* 1211.1Smycroft * Indirect system dependencies 1221.1Smycroft */ 1231.1Smycroft#if defined(SVR4) && !defined(__sgi) 1241.33Sfvdl#define USE_TERMIOS 1251.37Sfvdl#endif 1261.33Sfvdl 1271.33Sfvdl#ifdef SYSV 1281.33Sfvdl#define USE_SYSV_TERMIO 1291.80Spooka#endif 1301.1Smycroft 1311.22Sjdolecek#if defined(USE_POSIX_TERMIOS) && !defined(USE_TERMIOS) 1321.1Smycroft#define USE_TERMIOS 1331.14Scgd#endif 1341.1Smycroft 1351.1Smycroft/* 1361.32Sfvdl * Low-level ioctl, where it is needed or non-conflicting with termio/etc. 1371.36Sthorpej */ 1381.61Sbouyer#ifdef __QNX__ 1391.90Sdyoung#include <ioctl.h> 1401.52Sad#else 1411.36Sthorpej#include <sys/ioctl.h> 1421.36Sthorpej#endif 1431.35Sthorpej 1441.35Sthorpej/* 1451.1Smycroft * Terminal I/O includes (termio, termios, sgtty headers). 1461.42Syamt */ 1471.42Syamt#if defined(USE_POSIX_TERMIOS) && !defined(__hpux) 1481.44Syamt#include <termios.h> 1491.42Syamt#elif defined(USE_TERMIOS) 1501.42Syamt#include <termios.h> 1511.42Syamt/* this hacked termios support only works on SYSV */ 1521.42Syamt#define USE_ANY_SYSV_TERMIO 1531.42Syamt#define termio termios 1541.42Syamt#ifndef __CYGWIN__ 1551.42Syamt#undef TCGETA 1561.57Sad#define TCGETA TCGETS 1571.42Syamt#undef TCSETA 1581.54Syamt#define TCSETA TCSETS 1591.54Syamt#undef TCSETAW 1601.54Syamt#define TCSETAW TCSETSW 1611.54Syamt#endif 1621.54Syamt#elif defined(USE_SYSV_TERMIO) 1631.1Smycroft# define USE_ANY_SYSV_TERMIO 1641.85Sjym# ifdef Lynx 1651.85Sjym# include <termio.h> 1661.85Sjym# else 1671.60Syamt# include <sys/termio.h> 1681.60Syamt# endif 1691.1Smycroft#elif defined(SYSV) || defined(ISC) 1701.18Sthorpej# include <sys/termio.h> 1711.84Srmind#elif !defined(VMS) 1721.49Syamt# include <sgtty.h> 1731.35Sthorpej#endif /* USE_POSIX_TERMIOS */ 1741.35Sthorpej 1751.58Sad/* 1761.47Sad * Stream includes, which declare struct winsize or ttysize. 1771.62Sad */ 1781.62Sad#ifdef SYSV 1791.66Sad#ifdef USE_USG_PTYS 1801.66Sad#include <sys/stream.h> /* get typedef used in ptem.h */ 1811.79Sad#ifdef HAVE_SYS_PTEM_H 1821.1Smycroft#include <sys/ptem.h> /* get struct winsize */ 1831.39Sdsl#endif 1841.24Smycroft#endif /* USE_USG_PTYS */ 1851.1Smycroft#endif /* SYSV */ 1861.49Syamt 1871.1Smycroft/* 1881.55Sad * Special cases (structures and definitions that have to be adjusted). 1891.55Sad */ 1901.55Sad#if defined(__CYGWIN__) && !defined(TIOCSPGRP) 1911.1Smycroft#include <termios.h> 1921.1Smycroft#define TIOCSPGRP (_IOW('t', 118, pid_t)) 1931.1Smycroft#endif 1941.25Sfvdl 1951.25Sfvdl#ifdef __hpux 1961.25Sfvdl#include <sys/bsdtty.h> /* defines TIOCSLTC */ 1971.27Ssommerfe#endif 1981.27Ssommerfe 1991.27Ssommerfe#ifdef ISC 2001.1Smycroft#define TIOCGPGRP TCGETPGRP 2011.1Smycroft#define TIOCSPGRP TCSETPGRP 2021.1Smycroft#endif 2031.1Smycroft 2041.50Sad#ifdef Lynx 2051.1Smycroft#include <resource.h> 2061.1Smycroft#elif !(defined(SYSV) || defined(__linux__) || defined(VMS) || (defined(__QNX__)&&!defined(__QNXNTO__))) 2071.96Schristos#include <sys/resource.h> 2081.56Sad#endif 2091.56Sad 2101.60Syamt#ifdef macII 2111.1Smycroft#undef FIOCLEX 2121.1Smycroft#undef FIONCLEX 2131.5Smycroft#endif /* macII */ 2141.4Smycroft 2151.1Smycroft#if defined(__QNX__) || defined(__GNU__) || defined(__MVS__) || defined(__osf__) 2161.1Smycroft#undef TIOCSLTC /* <sgtty.h> conflicts with <termios.h> */ 2171.1Smycroft#undef TIOCSLTC 2181.33Sfvdl#endif 2191.33Sfvdl 2201.33Sfvdl#if defined (__sgi) || (defined(__linux__) && defined(__sparc__)) || defined(__UNIXWARE__) 2211.33Sfvdl#undef TIOCLSET /* defined, but not usable */ 2221.33Sfvdl#endif 2231.33Sfvdl 2241.33Sfvdl#if defined(sun) || defined(__UNIXWARE__) 2251.33Sfvdl#include <sys/filio.h> 2261.33Sfvdl#endif 2271.33Sfvdl 2281.33Sfvdl#if defined(TIOCSLTC) && ! (defined(__linux__) || defined(__MVS__) || defined(Lynx) || defined(SVR4)) 2291.33Sfvdl#define HAS_LTCHARS 2301.33Sfvdl#endif 2311.33Sfvdl 2321.1Smycroft#if !defined(TTYSIZE_STRUCT) 2331.1Smycroft#if defined(TIOCSWINSZ) 2341.1Smycroft#define USE_STRUCT_WINSIZE 1 2351.1Smycroft#define TTYSIZE_STRUCT struct winsize 2361.1Smycroft#define GET_TTYSIZE(fd, data) ioctl(fd, TIOCGWINSZ, (char *) &data) 2371.1Smycroft#define SET_TTYSIZE(fd, data) ioctl(fd, TIOCSWINSZ, (char *) &data) 2381.1Smycroft#define TTYSIZE_COLS(data) data.ws_col 2391.1Smycroft#define TTYSIZE_ROWS(data) data.ws_row 2401.1Smycroft#endif /* TIOCSWINSZ */ 2411.1Smycroft#endif /* TTYSIZE_STRUCT */ 2421.34Schristos 2431.38Schristos#ifndef USE_STRUCT_WINSIZE 2441.1Smycroft#error "There is a configuration error with struct winsize ifdef" 2451.1Smycroft#endif 2461.1Smycroft 2471.1Smycroft/* "resize" depends upon order of assignments in this macro */ 2481.1Smycroft#ifdef USE_STRUCT_WINSIZE 2491.1Smycroft#define setup_winsize(ts, rows, cols, height, width) \ 2501.1Smycroft (ts).ws_xpixel = (ttySize_t) (width), \ 2511.1Smycroft (ts).ws_ypixel = (ttySize_t) (height), \ 2521.1Smycroft TTYSIZE_ROWS(ts) = (ttySize_t) (rows), \ 2531.33Sfvdl TTYSIZE_COLS(ts) = (ttySize_t) (cols) 2541.61Sbouyer#else 2551.61Sbouyer#define setup_winsize(ts, rows, cols, height, width) \ 2561.61Sbouyer TTYSIZE_ROWS(ts) = (ttySize_t) (rows), \ 2571.1Smycroft TTYSIZE_COLS(ts) = (ttySize_t) (cols) 2581.61Sbouyer#endif 2591.1Smycroft 2601.32Sfvdl#if OPT_TRACE 2611.32Sfvdl 2621.40Syamt#ifdef USE_STRUCT_WINSIZE 2631.40Syamt#define trace_winsize(ts, id) \ 2641.40Syamt TRACE(("%s@%d, TTYSIZE %s chars %dx%d pixels %dx%d\n", \ 2651.35Sthorpej __FILE__, __LINE__, id, \ 2661.96Schristos TTYSIZE_ROWS(ts), TTYSIZE_COLS(ts), (ts).ws_ypixel, (ts).ws_xpixel)) 2671.72Sad#else 2681.49Syamt#define trace_winsize(ts, id) \ 2691.50Sad TRACE(("%s@%d, TTYSIZE %s chars %dx%d\n", __FILE__, __LINE__, id, \ 2701.60Syamt TTYSIZE_ROWS(ts), TTYSIZE_COLS(ts))) 2711.60Syamt#endif 2721.60Syamt 2731.60Syamt#define TRACE_GET_TTYSIZE(fd, id) { \ 2741.60Syamt TTYSIZE_STRUCT debug_ttysize; \ 2751.63Sad if (GET_TTYSIZE(fd, debug_ttysize) == 0) \ 2761.63Sad trace_winsize(debug_ttysize, id); \ 2771.74Sad else \ 2781.88Smatt TRACE(("%s@%d, TTYSIZE failed %s\n", __FILE__, __LINE__, strerror(errno))); \ 2791.68Sad } 2801.69Sad#else 2811.32Sfvdl#define trace_winsize(ts, id) /* nothing */ 2821.88Smatt#define TRACE_GET_TTYSIZE(fd, id) /* nothing */ 2831.32Sfvdl#endif 2841.32Sfvdl 2851.32Sfvdltypedef unsigned short ttySize_t; 2861.32Sfvdl 2871.32Sfvdl#ifdef USE_ANY_SYSV_TERMIO 2881.32Sfvdl#define TERMIO_STRUCT struct termio 2891.32Sfvdl#define ttySetAttr(fd, datap) ioctl(fd, TCSETA, datap) 2901.33Sfvdl#define ttyGetAttr(fd, datap) ioctl(fd, TCGETA, datap) 2911.33Sfvdl#define ttyFlush(fd) ioctl(fd, TCFLSH, 1) 2921.33Sfvdl#elif defined(USE_POSIX_TERMIOS) 2931.33Sfvdl#define TERMIO_STRUCT struct termios 2941.33Sfvdl#define ttySetAttr(fd, datap) tcsetattr(fd, TCSANOW, datap) 2951.33Sfvdl#define ttyGetAttr(fd, datap) tcgetattr(fd, datap) 2961.47Sad#define ttyFlush(fd) tcflush(fd, TCOFLUSH) 2971.47Sad#else 2981.46Syamt#error Neither termio or termios is enabled 2991.47Sad#endif /* USE_ANY_SYSV_TERMIO */ 3001.33Sfvdl 3011.71Sad#endif /* included_xterm_io_h */ 3021.71Sad