428
+ − 1 /* systty.h - System-dependent definitions for terminals.
+ − 2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
+ − 3
+ − 4 This file is part of XEmacs.
+ − 5
+ − 6 XEmacs is free software; you can redistribute it and/or modify it
+ − 7 under the terms of the GNU General Public License as published by the
+ − 8 Free Software Foundation; either version 2, or (at your option) any
+ − 9 later version.
+ − 10
+ − 11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
+ − 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ − 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ − 14 for more details.
+ − 15
+ − 16 You should have received a copy of the GNU General Public License
+ − 17 along with XEmacs; see the file COPYING. If not, write to
+ − 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ − 19 Boston, MA 02111-1307, USA. */
+ − 20
+ − 21 /* Synched up with: FSF 19.30. */
+ − 22
440
+ − 23 #ifndef INCLUDED_systty_h_
+ − 24 #define INCLUDED_systty_h_
428
+ − 25
+ − 26 #ifdef HAVE_TERMIOS
+ − 27 # define HAVE_TCATTR
+ − 28 #endif
+ − 29
+ − 30
+ − 31 /* Include the proper files. */
+ − 32
+ − 33 #ifdef HAVE_UNISTD_H
+ − 34 #include <unistd.h>
+ − 35 #endif
+ − 36
+ − 37 /* XEmacs: TERMIOS is mo' better than TERMIO so we use it if it's
+ − 38 there. Since TERMIO is backward-compatibility stuff if both it
+ − 39 and TERMIOS exist, it's more likely to be broken. */
+ − 40
+ − 41 #if defined (HAVE_TERMIOS)
+ − 42
+ − 43 /***** (1) The TERMIOS way (POSIX style) *****/
+ − 44
+ − 45 # if defined (_AIX) && defined (_I386)
+ − 46 # include <termios.h> /* termios.h needs to be before termio.h */
+ − 47 # include <termio.h>
+ − 48 # else
+ − 49 # if !defined (NO_TERMIO)
+ − 50 # include <termio.h>
+ − 51 # endif
+ − 52 # include <termios.h>
+ − 53 # endif /* _AIX && _I386 */
+ − 54 # ifndef INCLUDED_FCNTL
+ − 55 # define INCLUDED_FCNTL
+ − 56 # include <fcntl.h>
+ − 57 # endif
+ − 58
+ − 59 #elif defined (HAVE_TERMIO)
+ − 60
+ − 61 /***** (2) The TERMIO way (system V style) *****/
+ − 62
+ − 63 # ifdef __DGUX
+ − 64 # include <sys/ioctl.h>
+ − 65 # endif
+ − 66 # ifndef NO_TERMIO
+ − 67 # include <termio.h>
+ − 68 # endif /* not NO_TERMIO */
+ − 69 # ifndef INCLUDED_FCNTL
+ − 70 # define INCLUDED_FCNTL
+ − 71 # include <fcntl.h>
+ − 72 # endif
+ − 73
442
+ − 74 #elif defined (WIN32_NATIVE)
428
+ − 75
442
+ − 76 /***** (3) The WIN32_NATIVE way *****/
428
+ − 77
+ − 78 /* Nothing doing */
+ − 79
+ − 80 #else
+ − 81
+ − 82 /***** (4) The BSD way *****/
+ − 83
+ − 84 # ifdef linux /* XEmacs addition -- necessary? */
+ − 85 # include <bsd/sgtty.h>
+ − 86 # else
+ − 87 # include <sgtty.h>
+ − 88 # endif
+ − 89
+ − 90
+ − 91 #endif /* HAVE_TERMIOS */
+ − 92
+ − 93 /* XEmacs: I don't think we need the following crap. */
+ − 94 #ifdef __GNU_LIBRARY__
+ − 95 #include <termios.h>
+ − 96 #endif
+ − 97
+ − 98 /* Formerly there was a conditional that included sys/filio.h if
+ − 99 USG5_4 was defined, but this is already included in s/usg5-4.h */
+ − 100
+ − 101 /* Generally useful to include this file: */
+ − 102
+ − 103 /* But Sun OS has broken include files and doesn't want it included */
442
+ − 104 #if !defined (WIN32_NATIVE) && !defined (SUNOS4)
428
+ − 105 # include <sys/ioctl.h>
+ − 106 #endif
+ − 107 /* UNIPLUS systems may have FIONREAD. */
+ − 108 #ifdef UNIPLUS
+ − 109 #include <sys.ioctl.h>
+ − 110 #endif
+ − 111
+ − 112
+ − 113 /* ----------------------------------------------------- */
+ − 114 /* miscellaneous includes */
+ − 115 /* ----------------------------------------------------- */
+ − 116
535
+ − 117 #ifdef AIXHFT /* obsolete - only found in AIX version 3. */
428
+ − 118 /* Get files for keyboard remapping */
+ − 119 #define HFNKEYS 2
+ − 120 #include <sys/hft.h>
+ − 121 #include <sys/devinfo.h>
+ − 122 #endif
+ − 123
+ − 124 /* Include files for PTY's */
+ − 125
535
+ − 126 #if defined (HAVE_SYS_PTYIO_H) /* HP-UX */
428
+ − 127 #include <sys/ptyio.h>
+ − 128 #endif
+ − 129
535
+ − 130 #if defined (HAVE_PTY_H)
+ − 131 #include <pty.h>
+ − 132 #elif defined (HAVE_SYS_PTY_H)
428
+ − 133 #include <sys/pty.h>
+ − 134 #endif
+ − 135
+ − 136 /* XEmacs: removed some random if defined (pfa) crap for FASYNC (SIGIO).
+ − 137 We've cleaned SIGIO up. */
+ − 138
+ − 139
+ − 140 /* ----------------------------------------------------- */
+ − 141 /* inhibiting particular features */
+ − 142 /* ----------------------------------------------------- */
+ − 143
+ − 144
+ − 145 #if defined (XENIX) || defined (BROKEN_TIOCGETC)
+ − 146 #undef TIOCGETC /* Avoid confusing some conditionals that test this. */
+ − 147 #endif
+ − 148
+ − 149 /* XEmacs: SIGIO is cleaned up so we remove the crap here that messes
+ − 150 with it (and FIONREAD and FASYNC, which are related). */
+ − 151
+ − 152 #ifdef BROKEN_TIOCGWINSZ /* XEmacs addition */
+ − 153 #undef TIOCGWINSZ
+ − 154 #undef TIOCSWINSZ
+ − 155 #endif
+ − 156
+ − 157 /* On TERMIOS systems, the tcmumbleattr calls take care of these
+ − 158 parameters, and it's a bad idea to use them (on AIX, it makes the
+ − 159 tty hang for a long time). */
+ − 160 #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
+ − 161 #define HAVE_LTCHARS
+ − 162 #endif
+ − 163
+ − 164 #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
+ − 165 #define HAVE_TCHARS
+ − 166 #endif
+ − 167
+ − 168
+ − 169 /* ----------------------------------------------------- */
+ − 170 /* disabling terminal functions */
+ − 171 /* ----------------------------------------------------- */
+ − 172
+ − 173 /* Try to establish the correct character to disable terminal functions
+ − 174 in a system-independent manner.
+ − 175 We use the POSIX standard way to do this, and emulate on other systems. */
+ − 176
+ − 177 #ifndef _POSIX_VDISABLE
+ − 178 # if defined CDEL
+ − 179 # define _POSIX_VDISABLE CDEL
+ − 180 # else
+ − 181 # define _POSIX_VDISABLE 255
+ − 182 # endif
+ − 183 #endif /* ! _POSIX_VDISABLE */
+ − 184
+ − 185
+ − 186 /* ----------------------------------------------------- */
+ − 187 /* Get the number of characters queued for output */
+ − 188 /* ----------------------------------------------------- */
+ − 189
+ − 190 /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
+ − 191 queued for output to the terminal FD in *SIZE, if FD is a tty.
+ − 192 Returns -1 if there was an error (i.e. FD is not a tty), 0
+ − 193 otherwise. */
+ − 194 #ifdef TIOCOUTQ
+ − 195 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TIOCOUTQ, size)
+ − 196 #endif
+ − 197
+ − 198 #ifdef HAVE_TERMIO
+ − 199 #ifdef TCOUTQ
+ − 200 #undef EMACS_OUTQSIZE
+ − 201 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TCOUTQ, size)
+ − 202 #endif
+ − 203 #endif
+ − 204
+ − 205
+ − 206 /* -------------------------------------------------------------------- */
+ − 207 /* Manipulate a terminal's current (foreground) process group */
+ − 208 /* -------------------------------------------------------------------- */
+ − 209
442
+ − 210 /* EMACS_GET_TTY_PGRP(int FD, pid_t *PGID) sets *PGID to the terminal
+ − 211 FD's current foreground process group. Return -1 if there is an error.
+ − 212
+ − 213 EMACS_SET_TTY_PGRP(int FD, pid_t *PGID) sets the terminal FD's current
+ − 214 foreground process group to *PGID. Return -1 if there is an error.
428
+ − 215
442
+ − 216 We prefer using the ioctl (BSD) interface instead of its Posix
+ − 217 replacement tgetpgrp/tcsetpgrp since that is documented as being
+ − 218 restricted to processes sharing the same controlling tty. */
428
+ − 219
442
+ − 220 #if defined (TIOCGPGRP)
428
+ − 221
442
+ − 222 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCGPGRP, pgid)
+ − 223 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCSPGRP, pgid)
+ − 224
+ − 225 #elif defined (HAVE_TCGETPGRP)
428
+ − 226
442
+ − 227 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) (*(pgid) = tcgetpgrp (fd))
+ − 228 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) tcsetpgrp (fd, *(pgid))
428
+ − 229
442
+ − 230 #else
428
+ − 231
442
+ − 232 /* Just ignore this for now and hope for the best */
+ − 233 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) 0
+ − 234 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgif) 0
428
+ − 235
+ − 236 #endif
+ − 237
+ − 238 /* EMACS_GETPGRP (arg) returns the process group of the terminal. */
+ − 239
+ − 240 #ifdef GETPGRP_VOID
+ − 241 #define EMACS_GETPGRP(x) getpgrp()
+ − 242 #else
+ − 243 #define EMACS_GETPGRP(x) getpgrp(x)
+ − 244 #endif /* GETPGRP_VOID */
+ − 245
+ − 246 /* XEmacs backward-compatibility. Is 0 always a reasonable argument? */
+ − 247 #define EMACS_GET_PROCESS_GROUP() EMACS_GETPGRP (0)
+ − 248
+ − 249 /* XEmacs addition? */
+ − 250
+ − 251 /* EMACS_SEPARATE_PROCESS_GROUP () creates a separate process group for the
+ − 252 running process. */
+ − 253
+ − 254 /* EMACS_SET_PROCESS_GROUP () sets our process group as specified. */
+ − 255
+ − 256 /* POSIX calls for setpgid(), so we use it if it's available.
+ − 257 Otherwise use setpgrp(), in USG or BSD flavor. Note that
+ − 258 on newer systems, setpgrp() has unwanted effects (e.g.
+ − 259 creating a new session), so we want to avoid its use
+ − 260 if possible.
+ − 261
+ − 262 NOTE: On some older systems, we should consider using setpgrp2()
+ − 263 if it exists. This is sufficiently rare, though, that there
+ − 264 seems no point in autodetecting it. Currently dgux.h is the
+ − 265 only place where this has to be munged. */
+ − 266
+ − 267 #if defined (HAVE_SETPGID)
+ − 268 # define EMACS_SEPARATE_PROCESS_GROUP() setpgid (0, 0)
+ − 269 # define EMACS_SET_PROCESS_GROUP(pg) setpgid (0, pg)
+ − 270 #elif defined (USG)
+ − 271 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp ()
+ − 272 /* old (pre-SVR4) USG's don't provide any way to do this.
+ − 273 No big loss -- it just means that ^Z won't work right
+ − 274 if we're run from sh. */
+ − 275 # define EMACS_SET_PROCESS_GROUP(pg)
771
+ − 276 #elif defined (WIN32_NATIVE)
432
+ − 277 # define EMACS_SEPARATE_PROCESS_GROUP()
428
+ − 278 #else
+ − 279 /* Under NeXTstep, a process group of 0 is not the same as specifying
+ − 280 your own process ID, so we go ahead and specify it explicitly. */
+ − 281 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp (0, getpid ())
+ − 282 # define EMACS_SET_PROCESS_GROUP(pg) setpgrp (0, pg)
+ − 283 #endif
+ − 284
+ − 285
+ − 286 /* --------------------------------------------------------- */
+ − 287 /* Manipulate a TTY's input/output processing parameters */
+ − 288 /* --------------------------------------------------------- */
+ − 289
+ − 290 /* struct emacs_tty is a structure used to hold the current tty
+ − 291 parameters. If the terminal has several structures describing its
+ − 292 state, for example a struct tchars, a struct sgttyb, a struct
+ − 293 tchars, a struct ltchars, and a struct pagechars, struct
+ − 294 emacs_tty should contain an element for each parameter struct
+ − 295 that Emacs may change.
+ − 296
430
+ − 297 emacs_get_tty (int FD, struct emacs_tty *P) stores the parameters
428
+ − 298 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
+ − 299 into an error we couldn't deal with.
+ − 300
430
+ − 301 emacs_set_tty (int FD, struct emacs_tty *P, int flushp)
428
+ − 302 sets the parameters of the tty on FD according to the contents of
+ − 303 *P. If flushp is non-zero, we discard queued input to be
+ − 304 written before making the change.
+ − 305 Return 0 if all went well, and -1 if anything failed.
+ − 306
+ − 307 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
+ − 308 expands tabs to spaces upon output; in that case, there is no
+ − 309 advantage to using tabs over spaces. */
+ − 310
+ − 311
+ − 312 /* For each tty parameter structure that Emacs might want to save and restore,
+ − 313 - include an element for it in this structure, and
+ − 314 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
+ − 315 new members. */
+ − 316
+ − 317 struct emacs_tty {
+ − 318
+ − 319 /* There is always one of the following elements, so there is no need
+ − 320 for dummy get and set definitions. */
+ − 321 #ifdef HAVE_TCATTR
+ − 322 struct termios main;
+ − 323 #else /* !HAVE_TCATTR */
+ − 324 #ifdef HAVE_TERMIO
+ − 325 struct termio main;
+ − 326 #else /* !HAVE_TERMIO */
442
+ − 327 #ifdef WIN32_NATIVE
428
+ − 328 int main;
442
+ − 329 #else /* not WIN32_NATIVE */
428
+ − 330 struct sgttyb main;
442
+ − 331 #endif /* not WIN32_NATIVE */
428
+ − 332 #endif /* !HAVE_TERMIO */
+ − 333 #endif /* !HAVE_TCATTR */
+ − 334
+ − 335 /* If we have TERMIOS, we don't need to do this - they're taken care of
+ − 336 by the tc*attr calls. */
+ − 337 #ifndef HAVE_TERMIOS
+ − 338 #ifdef HAVE_LTCHARS
+ − 339 struct ltchars ltchars;
+ − 340 #endif /* HAVE_LTCHARS */
+ − 341
+ − 342 #ifdef HAVE_TCHARS
+ − 343 struct tchars tchars;
+ − 344 int lmode;
+ − 345 #endif /* HAVE_TCHARS */
+ − 346 #endif /* HAVE_TERMIOS */
+ − 347 };
+ − 348
430
+ − 349 int emacs_get_tty (int fd, struct emacs_tty *settings);
+ − 350 int emacs_set_tty (int fd, struct emacs_tty *settings, int flushp);
428
+ − 351
+ − 352
+ − 353 /* --------------------------------------------------------- */
+ − 354 /* Define EMACS_TTY_TABS_OK */
+ − 355 /* --------------------------------------------------------- */
+ − 356
513
+ − 357 #if defined (TABDLY) && defined (TAB3)
+ − 358 # define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
+ − 359 #elif defined (OXTABS)
+ − 360 # define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & OXTABS) != OXTABS)
428
+ − 361 #else
513
+ − 362 # define EMACS_TTY_TABS_OK(p) 1
+ − 363 #endif
428
+ − 364
440
+ − 365 #endif /* INCLUDED_systty_h_ */