1 /* systty.h - System-dependent definitions for terminals.
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of XEmacs.
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
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
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. */
21 /* Synched up with: FSF 19.30. */
23 #ifndef _XEMACS_SYSTTY_H_
24 #define _XEMACS_SYSTTY_H_
30 /* If we defined these before and we are about to redefine them,
31 prevent alarming warnings. */
54 /* Include the proper files. */
56 /* XEmacs: TERMIOS is mo' better than TERMIO so we use it if it's
57 there. Since TERMIO is backward-compatibility stuff if both it
58 and TERMIOS exist, it's more likely to be broken. */
60 #if defined (HAVE_TERMIOS)
62 /***** (1) The TERMIOS way (POSIX style) *****/
64 # if defined (_AIX) && defined (_I386)
65 # include <termios.h> /* termios.h needs to be before termio.h */
68 # if !defined (NO_TERMIO)
72 # endif /* _AIX && _I386 */
73 # ifndef INCLUDED_FCNTL
74 # define INCLUDED_FCNTL
78 #elif defined (HAVE_TERMIO)
80 /***** (2) The TERMIO way (system V style) *****/
83 # include <sys/ioctl.h>
87 # endif /* not NO_TERMIO */
88 # ifndef INCLUDED_FCNTL
89 # define INCLUDED_FCNTL
93 #elif defined (DOS_NT)
95 /***** (3) The MSDOS/NT way *****/
101 /***** (4) The BSD way *****/
103 # ifdef linux /* XEmacs addition -- necessary? */
104 # include <bsd/sgtty.h>
110 #endif /* HAVE_TERMIOS */
112 /* XEmacs: I don't think we need the following crap. */
113 #ifdef __GNU_LIBRARY__
117 /* Formerly there was a conditional that included sys/filio.h if
118 USG5_4 was defined, but this is already included in s/usg5-4.h */
120 /* Generally useful to include this file: */
122 /* But Sun OS has broken include files and doesn't want it included */
123 #if !defined (DOS_NT) && !defined (WIN32) && !defined (SUNOS4)
124 # include <sys/ioctl.h>
126 /* UNIPLUS systems may have FIONREAD. */
128 #include <sys.ioctl.h>
132 /* ----------------------------------------------------- */
133 /* miscellaneous includes */
134 /* ----------------------------------------------------- */
137 /* Get files for keyboard remapping */
140 #include <sys/devinfo.h>
143 /* XEmacs: We don't support BSD 4.1 any more */
146 #include <sys/bsdtty.h>
149 /* Include files for PTY's */
151 #if defined (HPUX) && defined (HAVE_PTYS)
152 #include <sys/ptyio.h>
160 # include <sys/types.h>
161 # include <sys/tty.h>
163 # include <sys/ttyhw.h>
164 # include <sys/stream.h>
167 # include <sys/pty.h>
171 /* XEmacs: removed some random if defined (pfa) crap for FASYNC (SIGIO).
172 We've cleaned SIGIO up. */
175 /* ----------------------------------------------------- */
176 /* inhibiting particular features */
177 /* ----------------------------------------------------- */
184 #if defined (XENIX) || defined (BROKEN_TIOCGETC)
185 #undef TIOCGETC /* Avoid confusing some conditionals that test this. */
188 /* XEmacs: SIGIO is cleaned up so we remove the crap here that messes
189 with it (and FIONREAD and FASYNC, which are related). */
191 #ifdef BROKEN_TIOCGWINSZ /* XEmacs addition */
196 #ifdef BROKEN_O_NONBLOCK /* XEmacs addition */
198 #endif /* BROKEN_O_NONBLOCK */
200 /* On TERMIOS systems, the tcmumbleattr calls take care of these
201 parameters, and it's a bad idea to use them (on AIX, it makes the
202 tty hang for a long time). */
203 #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
207 #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
212 /* ----------------------------------------------------- */
213 /* disabling terminal functions */
214 /* ----------------------------------------------------- */
216 /* Try to establish the correct character to disable terminal functions
217 in a system-independent manner. Note that USG (at least) define
218 _POSIX_VDISABLE as 0! */
220 #ifdef _POSIX_VDISABLE
221 #define CDISABLE _POSIX_VDISABLE
222 #else /* not _POSIX_VDISABLE */
225 #define CDISABLE CDEL
228 #endif /* not CDEL */
229 #endif /* not _POSIX_VDISABLE */
232 /* ----------------------------------------------------- */
233 /* Get the number of characters queued for output */
234 /* ----------------------------------------------------- */
236 /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
237 queued for output to the terminal FD in *SIZE, if FD is a tty.
238 Returns -1 if there was an error (i.e. FD is not a tty), 0
241 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TIOCOUTQ, size)
246 #undef EMACS_OUTQSIZE
247 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TCOUTQ, size)
252 /* -------------------------------------------------------------------- */
253 /* Manipulate a terminal's current (foreground) process group */
254 /* -------------------------------------------------------------------- */
256 /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current
257 controlling process group.
259 EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's
260 current process group. Return -1 if there is an error.
262 EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's
263 current process group to *PGID. Return -1 if there is an error. */
265 /* HPUX tty process group stuff doesn't work, says the anonymous voice
267 /* But HPUX people say it does, so I've removed it. --ben */
269 # define EMACS_HAVE_TTY_PGRP
272 # define EMACS_HAVE_TTY_PGRP
276 #ifdef EMACS_HAVE_TTY_PGRP
278 #if defined (HAVE_TERMIOS) && ! defined (BSD_TERMIOS)
280 /* Resist the urge to insert needless extra parentheses. */
281 #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp (fd))
282 #define EMACS_SET_TTY_PGRP(fd, pgid) tcsetpgrp (fd, *(pgid))
284 #elif defined (TIOCSPGRP)
286 #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid)))
287 #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid)))
291 #endif /* EMACS_HAVE_TTY_PGRP */
293 #ifndef EMACS_GET_TTY_PGRP
295 /* Just ignore this for now and hope for the best */
296 #define EMACS_GET_TTY_PGRP(fd, pgid) 0
297 #define EMACS_SET_TTY_PGRP(fd, pgif) 0
301 /* XEmacs interim backward-compatibility */
302 #define EMACS_GET_TTY_PROCESS_GROUP EMACS_GET_TTY_PGRP
303 #define EMACS_SET_TTY_PROCESS_GROUP EMACS_SET_TTY_PGRP
305 /* EMACS_GETPGRP (arg) returns the process group of the terminal. */
308 #define EMACS_GETPGRP(x) getpgrp()
310 #define EMACS_GETPGRP(x) getpgrp(x)
311 #endif /* GETPGRP_VOID */
313 /* XEmacs backward-compatibility. Is 0 always a reasonable argument? */
314 #define EMACS_GET_PROCESS_GROUP() EMACS_GETPGRP (0)
316 /* XEmacs addition? */
318 /* EMACS_SEPARATE_PROCESS_GROUP () creates a separate process group for the
321 /* EMACS_SET_PROCESS_GROUP () sets our process group as specified. */
323 /* POSIX calls for setpgid(), so we use it if it's available.
324 Otherwise use setpgrp(), in USG or BSD flavor. Note that
325 on newer systems, setpgrp() has unwanted effects (e.g.
326 creating a new session), so we want to avoid its use
329 NOTE: On some older systems, we should consider using setpgrp2()
330 if it exists. This is sufficiently rare, though, that there
331 seems no point in autodetecting it. Currently dgux.h is the
332 only place where this has to be munged. */
334 #if defined (HAVE_SETPGID)
335 # define EMACS_SEPARATE_PROCESS_GROUP() setpgid (0, 0)
336 # define EMACS_SET_PROCESS_GROUP(pg) setpgid (0, pg)
338 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp ()
339 /* old (pre-SVR4) USG's don't provide any way to do this.
340 No big loss -- it just means that ^Z won't work right
341 if we're run from sh. */
342 # define EMACS_SET_PROCESS_GROUP(pg)
344 /* Under NeXTstep, a process group of 0 is not the same as specifying
345 your own process ID, so we go ahead and specify it explicitly. */
346 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp (0, getpid ())
347 # define EMACS_SET_PROCESS_GROUP(pg) setpgrp (0, pg)
351 /* --------------------------------------------------------- */
352 /* Manipulate a TTY's input/output processing parameters */
353 /* --------------------------------------------------------- */
355 /* struct emacs_tty is a structure used to hold the current tty
356 parameters. If the terminal has several structures describing its
357 state, for example a struct tchars, a struct sgttyb, a struct
358 tchars, a struct ltchars, and a struct pagechars, struct
359 emacs_tty should contain an element for each parameter struct
360 that Emacs may change.
362 EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the parameters
363 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
364 into an error we couldn't deal with.
366 EMACS_SET_TTY (int FD, struct emacs_tty *P, int flushp)
367 sets the parameters of the tty on FD according to the contents of
368 *P. If flushp is non-zero, we discard queued input to be
369 written before making the change.
370 Return 0 if all went well, and -1 if anything failed.
372 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
373 expands tabs to spaces upon output; in that case, there is no
374 advantage to using tabs over spaces. */
377 /* For each tty parameter structure that Emacs might want to save and restore,
378 - include an element for it in this structure, and
379 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
384 /* There is always one of the following elements, so there is no need
385 for dummy get and set definitions. */
388 #else /* !HAVE_TCATTR */
391 #else /* !HAVE_TERMIO */
394 #else /* not DOS_NT */
396 #endif /* not DOS_NT */
397 #endif /* !HAVE_TERMIO */
398 #endif /* !HAVE_TCATTR */
400 /* If we have TERMIOS, we don't need to do this - they're taken care of
401 by the tc*attr calls. */
404 struct ltchars ltchars;
405 #endif /* HAVE_LTCHARS */
408 struct tchars tchars;
410 #endif /* HAVE_TCHARS */
411 #endif /* HAVE_TERMIOS */
414 /* Define EMACS_GET_TTY and EMACS_SET_TTY,
415 the macros for reading and setting parts of `struct emacs_tty'.
417 These got pretty unmanageable (huge macros are hard to debug), and
418 finally needed some code which couldn't be done as part of an
419 expression, so we moved them out to their own functions in sysdep.c. */
420 #define EMACS_GET_TTY(fd, p) emacs_get_tty (fd, p)
421 #define EMACS_SET_TTY(fd, p, waitp) emacs_set_tty (fd, p, waitp)
424 /* --------------------------------------------------------- */
425 /* Define EMACS_TTY_TABS_OK */
426 /* --------------------------------------------------------- */
431 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
433 #define EMACS_TTY_TABS_OK(p) 1
436 #else /* not def HAVE_TERMIOS */
439 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
441 #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
443 #define EMACS_TTY_TABS_OK(p) 0
444 #else /* not DOS_NT */
445 #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS)
446 #endif /* not DOS_NT */
448 #endif /* not def HAVE_TERMIO */
449 #endif /* not def HAVE_TERMIOS */
451 #endif /* _XEMACS_SYSTTY_H_ */