| 1 | /* systty.h - System-dependent definitions for terminals. |
| 2 | Copyright (C) 1992 Free Software Foundation, Inc. |
| 3 | |
| 4 | This file is part of GNU Emacs. |
| 5 | |
| 6 | GNU Emacs is free software; you can redistribute it and/or modify |
| 7 | it under the terms of the GNU General Public License as published by |
| 8 | the Free Software Foundation; either version 1, or (at your option) |
| 9 | any later version. |
| 10 | |
| 11 | GNU Emacs is distributed in the hope that it will be useful, |
| 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | GNU General Public License for more details. |
| 15 | |
| 16 | You should have received a copy of the GNU General Public License |
| 17 | along with GNU Emacs; see the file COPYING. If not, write to |
| 18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
| 19 | |
| 20 | \f |
| 21 | /* Include the proper files. */ |
| 22 | #ifdef HAVE_TERMIO |
| 23 | #include <termio.h> |
| 24 | #include <fcntl.h> |
| 25 | #else |
| 26 | #ifdef HAVE_TERMIOS |
| 27 | #include <termio.h> |
| 28 | #include <termios.h> |
| 29 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ |
| 30 | #ifndef VMS |
| 31 | #include <sgtty.h> |
| 32 | #else /* VMS */ |
| 33 | #include <descrip.h> |
| 34 | static struct iosb |
| 35 | { |
| 36 | short status; |
| 37 | short offset; |
| 38 | short termlen; |
| 39 | short term; |
| 40 | } input_iosb; |
| 41 | |
| 42 | extern int waiting_for_ast; |
| 43 | extern int stop_input; |
| 44 | extern int input_ef = 0; |
| 45 | extern int timer_ef = 0; |
| 46 | extern int process_ef = 0; |
| 47 | extern int input_eflist; |
| 48 | extern int timer_eflist; |
| 49 | |
| 50 | static $DESCRIPTOR (input_dsc, "TT"); |
| 51 | static int terminator_mask[2] = { 0, 0 }; |
| 52 | |
| 53 | static struct sensemode { |
| 54 | short status; |
| 55 | unsigned char xmit_baud; |
| 56 | unsigned char rcv_baud; |
| 57 | unsigned char crfill; |
| 58 | unsigned char lffill; |
| 59 | unsigned char parity; |
| 60 | unsigned char unused; |
| 61 | char class; |
| 62 | char type; |
| 63 | short scr_wid; |
| 64 | unsigned long tt_char : 24, scr_len : 8; |
| 65 | unsigned long tt2_char; |
| 66 | } sensemode_iosb; |
| 67 | #endif /* VMS */ |
| 68 | #endif /* not HAVE_TERMIOS */ |
| 69 | #endif /* not HAVE_TERMIO */ |
| 70 | |
| 71 | #ifdef AIX |
| 72 | /* Get files for keyboard remapping */ |
| 73 | #define HFNKEYS 2 |
| 74 | #include <sys/hft.h> |
| 75 | #include <sys/devinfo.h> |
| 76 | #endif |
| 77 | |
| 78 | /* Get rid of LLITOUT in 4.1, since it is said to stimulate kernel bugs. */ |
| 79 | #ifdef BSD4_1 |
| 80 | #undef LLITOUT |
| 81 | #define LLITOUT 0 |
| 82 | #endif /* 4.1 */ |
| 83 | |
| 84 | #ifdef NEED_BSDTTY |
| 85 | #include <sys/bsdtty.h> |
| 86 | #endif |
| 87 | |
| 88 | #if defined (HPUX) && defined (HAVE_PTYS) |
| 89 | #include <sys/ptyio.h> |
| 90 | #endif |
| 91 | |
| 92 | #ifdef AIX |
| 93 | #include <sys/pty.h> |
| 94 | #include <unistd.h> |
| 95 | #endif /* AIX */ |
| 96 | |
| 97 | #ifdef SYSV_PTYS |
| 98 | #include <sys/tty.h> |
| 99 | #ifdef titan |
| 100 | #include <sys/ttyhw.h> |
| 101 | #include <sys/stream.h> |
| 102 | #endif |
| 103 | #include <sys/pty.h> |
| 104 | #endif |
| 105 | |
| 106 | /* saka@pfu.fujitsu.co.JP writes: |
| 107 | FASYNC defined in this file. But, FASYNC don't working. |
| 108 | so no problem, because unrequest_sigio only need. */ |
| 109 | #if defined (pfa) |
| 110 | #include <sys/file.h> |
| 111 | #endif |
| 112 | |
| 113 | \f |
| 114 | /* Special cases - inhibiting the use of certain features. */ |
| 115 | |
| 116 | #ifdef APOLLO |
| 117 | #undef TIOCSTART |
| 118 | #endif |
| 119 | |
| 120 | #ifdef XENIX |
| 121 | #undef TIOCGETC /* Avoid confusing some conditionals that test this. */ |
| 122 | #endif |
| 123 | |
| 124 | #ifdef BROKEN_TIOCGETC |
| 125 | #undef TIOCGETC /* Avoid confusing some conditionals that test this. */ |
| 126 | #endif |
| 127 | |
| 128 | /* UNIPLUS systems may have FIONREAD. */ |
| 129 | #ifdef UNIPLUS |
| 130 | #include <sys.ioctl.h> |
| 131 | #endif |
| 132 | |
| 133 | /* Allow m- file to inhibit use of FIONREAD. */ |
| 134 | #ifdef BROKEN_FIONREAD |
| 135 | #undef FIONREAD |
| 136 | #undef ASYNC |
| 137 | #endif |
| 138 | |
| 139 | /* Interupt input is not used if there is no FIONREAD. */ |
| 140 | #ifndef FIONREAD |
| 141 | #undef SIGIO |
| 142 | #endif |
| 143 | |
| 144 | \f |
| 145 | /* Try to establish the correct character to disable terminal functions |
| 146 | in a system-independent manner. Note that USG (at least) define |
| 147 | _POSIX_VDISABLE as 0! */ |
| 148 | |
| 149 | #ifdef _POSIX_VDISABLE |
| 150 | #define CDISABLE _POSIX_VDISABLE |
| 151 | #else /* not _POSIX_VDISABLE */ |
| 152 | #ifdef CDEL |
| 153 | #define CDISABLE CDEL |
| 154 | #else /* not CDEL */ |
| 155 | #define CDISABLE 255 |
| 156 | #endif /* not CDEL */ |
| 157 | #endif /* not _POSIX_VDISABLE */ |
| 158 | \f |
| 159 | /* Get the number of characters queued for output. */ |
| 160 | |
| 161 | /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters |
| 162 | queued for output to the terminal FD in *SIZE, if FD is a tty. |
| 163 | Returns -1 if there was an error (i.e. FD is not a tty), 0 |
| 164 | otherwise. */ |
| 165 | #ifdef TIOCOUTQ |
| 166 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size))) |
| 167 | #endif |
| 168 | |
| 169 | #ifdef HAVE_TERMIO |
| 170 | #ifdef TCOUTQ |
| 171 | #undef EMACS_OUTQSIZE |
| 172 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TCOUTQ, (size))) |
| 173 | #endif |
| 174 | #endif |
| 175 | |
| 176 | \f |
| 177 | /* Manipulate a terminal's current process group. */ |
| 178 | |
| 179 | /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current |
| 180 | controlling process group. |
| 181 | |
| 182 | EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's |
| 183 | current process group. Return -1 if there is an error. |
| 184 | |
| 185 | EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's |
| 186 | current process group to *PGID. Return -1 if there is an error. */ |
| 187 | |
| 188 | #ifdef HPUX |
| 189 | /* HPUX tty process group stuff doesn't work, says the anonymous voice |
| 190 | from the past. */ |
| 191 | #else |
| 192 | #ifdef TIOCGPGRP |
| 193 | #define EMACS_HAVE_TTY_PGRP |
| 194 | #else |
| 195 | #ifdef HAVE_TERMIOS |
| 196 | #define EMACS_HAVE_TTY_PGRP |
| 197 | #endif |
| 198 | #endif |
| 199 | #endif |
| 200 | |
| 201 | #ifdef EMACS_HAVE_TTY_PGRP |
| 202 | |
| 203 | #ifdef HAVE_TERMIOS |
| 204 | |
| 205 | #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp ((fd))) |
| 206 | #define EMACS_SET_TTY_PGRP(fd, pgid) (*(pgid) = tcsetpgrp ((fd))) |
| 207 | |
| 208 | #else |
| 209 | #ifdef TIOCSPGRP |
| 210 | |
| 211 | #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid))) |
| 212 | #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid))) |
| 213 | |
| 214 | #endif |
| 215 | #endif |
| 216 | |
| 217 | #else |
| 218 | |
| 219 | /* Just ignore this for now and hope for the best */ |
| 220 | #define EMACS_GET_TTY_PGRP(fd, pgid) 0 |
| 221 | #define EMACS_SET_TTY_PGRP(fd, pgif) 0 |
| 222 | |
| 223 | #endif |
| 224 | |
| 225 | \f |
| 226 | /* Manipulate a TTY's input/output processing parameters. */ |
| 227 | |
| 228 | /* struct emacs_tty is a structure used to hold the current tty |
| 229 | parameters. If the terminal has several structures describing its |
| 230 | state, for example a struct tchars, a struct sgttyb, a struct |
| 231 | tchars, a struct ltchars, and a struct pagechars, struct |
| 232 | emacs_tty should contain an element for each parameter struct |
| 233 | that Emacs may change. |
| 234 | |
| 235 | EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the |
| 236 | parameters of the tty on FD in *P. |
| 237 | |
| 238 | EMACS_SET_TTY (int FD, struct emacs_tty *P, int waitp) |
| 239 | sets the parameters of the tty on FD according to the contents of |
| 240 | *P. If waitp is non-zero, we wait for all queued output to be |
| 241 | written before making the change; otherwise, we forget any queued |
| 242 | input and make the change immediately. |
| 243 | |
| 244 | EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel |
| 245 | expands tabs to spaces upon output; in that case, there is no |
| 246 | advantage to using tabs over spaces. */ |
| 247 | |
| 248 | |
| 249 | |
| 250 | /* For each tty parameter structure that Emacs might want to save and restore, |
| 251 | - include an element for it in this structure, |
| 252 | - define a pair of numbered macros to get and set it and return |
| 253 | true iff the call succeeded, |
| 254 | - give alternative definitions for when the component is not implemented |
| 255 | which always succeed, and |
| 256 | - extend the definition of EMACS_{GET,SET}_TTY_CHARS to include the |
| 257 | new macros. */ |
| 258 | |
| 259 | struct emacs_tty { |
| 260 | |
| 261 | /* There is always one of the following elements, so there is no need |
| 262 | for dummy get and set definitions. */ |
| 263 | #ifdef HAVE_TERMIOS |
| 264 | struct termios main; |
| 265 | #else |
| 266 | #ifdef HAVE_TERMIO |
| 267 | struct termio main; |
| 268 | #else |
| 269 | #ifdef VMS |
| 270 | struct sensemode main; |
| 271 | #else |
| 272 | struct sgttyb main; |
| 273 | #endif |
| 274 | #endif |
| 275 | #endif |
| 276 | |
| 277 | #ifdef HAVE_TERMIOS |
| 278 | #define HAVE_TCATTR |
| 279 | #endif |
| 280 | |
| 281 | #ifdef HAVE_TCATTR |
| 282 | |
| 283 | #define EMACS_GET_TTY_1(fd, p) (tcgetattr ((fd), &(p)->main) != -1) |
| 284 | #define EMACS_SET_TTY_1(fd, p, waitp) \ |
| 285 | (tcsetattr ((fd), (waitp) ? TCSAFLUSH : TCSADRAIN, &(p)->main) != -1) |
| 286 | |
| 287 | #else |
| 288 | #ifdef HAVE_TERMIO |
| 289 | |
| 290 | #define EMACS_GET_TTY_1(fd, p) (ioctl ((fd), TCGETA, &(p)->main) != -1) |
| 291 | #define EMACS_SET_TTY_1(fd, p, waitp) \ |
| 292 | (ioctl ((fd), (waitp) ? TCSETAW : TCSETAF, &(p)->main) != -1) |
| 293 | |
| 294 | #else |
| 295 | #ifdef VMS |
| 296 | |
| 297 | /* These definitions will really only work in sysdep.c, because of their |
| 298 | use of input_iosb. I don't know enough about VMS QIO to fix this. */ |
| 299 | #define EMACS_GET_TTY_1(fd, p) \ |
| 300 | (1 & SYS$QIOW (0, (fd), IO$_SENSEMODE, (p), 0, 0, \ |
| 301 | &(p)->main.class, 12, 0, 0, 0, 0)) |
| 302 | #define EMACS_SET_TTY_1(fd, p, waitp) \ |
| 303 | (1 & SYS$QIOW (0, (fd), IO$_SETMODE, &input_iosb, 0, 0, \ |
| 304 | &(p)->main.class, 12, 0, 0, 0, 0)) |
| 305 | |
| 306 | #else |
| 307 | |
| 308 | #define EMACS_GET_TTY_1(fd, p) (ioctl ((fd), TIOCGETP, &(p)->main) != -1) |
| 309 | #define EMACS_SET_TTY_1(fd, p, waitp) \ |
| 310 | (ioctl ((fd), (waitp) ? TIOCSETP : TIOCSETN, &(p)->main) != -1) |
| 311 | |
| 312 | #endif |
| 313 | #endif |
| 314 | #endif |
| 315 | |
| 316 | #ifdef TIOCGLTC |
| 317 | struct ltchars ltchars; |
| 318 | #define EMACS_GET_TTY_2(fd, p) \ |
| 319 | (ioctl ((fd), TIOCGLTC, &(p)->ltchars) != -1) |
| 320 | #define EMACS_SET_TTY_2(fd, p, waitp) \ |
| 321 | (ioctl ((fd), TIOCSLTC, &(p)->ltchars) != -1) |
| 322 | #else |
| 323 | #define EMACS_GET_TTY_2(fd, p) 1 |
| 324 | #define EMACS_SET_TTY_2(fd, p, waitp) 1 |
| 325 | #endif /* TIOCGLTC */ |
| 326 | |
| 327 | #ifdef TIOCGETC |
| 328 | struct tchars tchars; |
| 329 | int lmode; |
| 330 | #define EMACS_GET_TTY_3(fd, p) \ |
| 331 | (ioctl ((fd), TIOCGETC, &(p)->tchars) != -1 \ |
| 332 | && ioctl ((fd), TIOCLGET, &(p)->lmode) != -1) |
| 333 | #define EMACS_SET_TTY_3(fd, p, waitp) \ |
| 334 | (ioctl ((fd), TIOCSETC, &(p)->tchars) != -1 \ |
| 335 | && ioctl ((fd), TIOCLSET, &(p)->lmode) != -1) |
| 336 | #else |
| 337 | #define EMACS_GET_TTY_3(fd, p) 1 |
| 338 | #define EMACS_SET_TTY_3(fd, p, waitp) 1 |
| 339 | #endif /* TIOCGLTC */ |
| 340 | |
| 341 | }; |
| 342 | |
| 343 | /* Define these to be a concatenation of all the EMACS_{GET,SET}_TTY_n |
| 344 | macros. */ |
| 345 | #define EMACS_GET_TTY(fd, tc) \ |
| 346 | (EMACS_GET_TTY_1 (fd, tc) \ |
| 347 | && EMACS_GET_TTY_2 (fd, tc) \ |
| 348 | && EMACS_GET_TTY_3 (fd, tc)) |
| 349 | |
| 350 | #define EMACS_SET_TTY(fd, tc, waitp) \ |
| 351 | (EMACS_SET_TTY_1 (fd, tc, waitp) \ |
| 352 | && EMACS_SET_TTY_2 (fd, tc, waitp) \ |
| 353 | && EMACS_SET_TTY_3 (fd, tc, waitp)) |
| 354 | |
| 355 | |
| 356 | #ifdef HAVE_TERMIOS |
| 357 | |
| 358 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) |
| 359 | |
| 360 | #else /* not def HAVE_TERMIOS */ |
| 361 | #ifdef HAVE_TERMIO |
| 362 | |
| 363 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) |
| 364 | |
| 365 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ |
| 366 | #ifdef VMS |
| 367 | |
| 368 | #define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0) |
| 369 | |
| 370 | #else |
| 371 | |
| 372 | #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS) |
| 373 | |
| 374 | #endif /* not def VMS */ |
| 375 | #endif /* not def HAVE_TERMIO */ |
| 376 | #endif /* not def HAVE_TERMIOS */ |