1 /* systty.h - System-dependent definitions for terminals.
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
4 This file is part of SXEmacs
6 SXEmacs 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 3 of the License, or
9 (at your option) any later version.
11 SXEmacs 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.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 /* Synched up with: FSF 19.30. */
22 #ifndef INCLUDED_systty_h_
23 #define INCLUDED_systty_h_
29 /* If we defined these before and we are about to redefine them,
30 prevent alarming warnings. */
53 /* Include the proper files. */
59 /* XEmacs: TERMIOS is mo' better than TERMIO so we use it if it's
60 there. Since TERMIO is backward-compatibility stuff if both it
61 and TERMIOS exist, it's more likely to be broken. */
63 #if defined (HAVE_TERMIOS)
65 /***** (1) The TERMIOS way (POSIX style) *****/
67 # if defined (_AIX) && defined (_I386)
68 # include <termios.h> /* termios.h needs to be before termio.h */
71 # if !defined (NO_TERMIO)
75 # endif /* _AIX && _I386 */
76 # ifndef INCLUDED_FCNTL
77 # define INCLUDED_FCNTL
81 #elif defined (HAVE_TERMIO)
83 /***** (2) The TERMIO way (system V style) *****/
86 # include <sys/ioctl.h>
90 # endif /* not NO_TERMIO */
91 # ifndef INCLUDED_FCNTL
92 # define INCLUDED_FCNTL
98 /***** (4) The BSD way *****/
100 # ifdef linux /* XEmacs addition -- necessary? */
101 # include <bsd/sgtty.h>
106 #endif /* HAVE_TERMIOS */
108 /* XEmacs: I don't think we need the following crap. */
109 #ifdef __GNU_LIBRARY__
113 /* Formerly there was a conditional that included sys/filio.h if
114 USG5_4 was defined, but this is already included in s/usg5-4.h */
116 /* Generally useful to include this file: */
118 /* But Sun OS has broken include files and doesn't want it included */
119 #if !defined (SUNOS4)
120 # include <sys/ioctl.h>
122 /* UNIPLUS systems may have FIONREAD. */
124 #include <sys.ioctl.h>
127 /* ----------------------------------------------------- */
128 /* miscellaneous includes */
129 /* ----------------------------------------------------- */
132 /* Get files for keyboard remapping */
135 #include <sys/devinfo.h>
138 /* XEmacs: We don't support BSD 4.1 any more */
141 #include <sys/bsdtty.h>
144 /* Include files for PTY's */
146 #if defined (HPUX) && defined (HAVE_PTYS)
147 #include <sys/ptyio.h>
155 # include <sys/types.h>
156 # include <sys/tty.h>
158 # include <sys/ttyhw.h>
159 # include <sys/stream.h>
162 # include <sys/pty.h>
166 /* XEmacs: removed some random if defined (pfa) crap for FASYNC (SIGIO).
167 We've cleaned SIGIO up. */
169 /* ----------------------------------------------------- */
170 /* inhibiting particular features */
171 /* ----------------------------------------------------- */
173 #if defined (XENIX) || defined (BROKEN_TIOCGETC)
174 #undef TIOCGETC /* Avoid confusing some conditionals that test this. */
177 /* XEmacs: SIGIO is cleaned up so we remove the crap here that messes
178 with it (and FIONREAD and FASYNC, which are related). */
180 #ifdef BROKEN_TIOCGWINSZ /* XEmacs addition */
185 /* On TERMIOS systems, the tcmumbleattr calls take care of these
186 parameters, and it's a bad idea to use them (on AIX, it makes the
187 tty hang for a long time). */
188 #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
192 #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
196 /* ----------------------------------------------------- */
197 /* disabling terminal functions */
198 /* ----------------------------------------------------- */
200 /* Try to establish the correct character to disable terminal functions
201 in a system-independent manner.
202 We use the POSIX standard way to do this, and emulate on other systems. */
204 #ifndef _POSIX_VDISABLE
206 # define _POSIX_VDISABLE CDEL
208 # define _POSIX_VDISABLE 255
210 #endif /* ! _POSIX_VDISABLE */
212 /* ----------------------------------------------------- */
213 /* Get the number of characters queued for output */
214 /* ----------------------------------------------------- */
216 /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
217 queued for output to the terminal FD in *SIZE, if FD is a tty.
218 Returns -1 if there was an error (i.e. FD is not a tty), 0
221 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TIOCOUTQ, size)
226 #undef EMACS_OUTQSIZE
227 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TCOUTQ, size)
231 /* -------------------------------------------------------------------- */
232 /* Manipulate a terminal's current (foreground) process group */
233 /* -------------------------------------------------------------------- */
235 /* EMACS_GET_TTY_PGRP(int FD, pid_t *PGID) sets *PGID to the terminal
236 FD's current foreground process group. Return -1 if there is an error.
238 EMACS_SET_TTY_PGRP(int FD, pid_t *PGID) sets the terminal FD's current
239 foreground process group to *PGID. Return -1 if there is an error.
241 We prefer using the ioctl (BSD) interface instead of its Posix
242 replacement tgetpgrp/tcsetpgrp since that is documented as being
243 restricted to processes sharing the same controlling tty. */
245 #if defined (TIOCGPGRP)
247 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCGPGRP, pgid)
248 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCSPGRP, pgid)
250 #elif defined (HAVE_TCGETPGRP)
252 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) (*(pgid) = tcgetpgrp (fd))
253 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) tcsetpgrp (fd, *(pgid))
257 /* Just ignore this for now and hope for the best */
258 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) 0
259 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgif) 0
263 /* EMACS_GETPGRP (arg) returns the process group of the terminal. */
266 #define EMACS_GETPGRP(x) getpgrp()
268 #define EMACS_GETPGRP(x) getpgrp(x)
269 #endif /* GETPGRP_VOID */
271 /* XEmacs backward-compatibility. Is 0 always a reasonable argument? */
272 #define EMACS_GET_PROCESS_GROUP() EMACS_GETPGRP (0)
274 /* XEmacs addition? */
276 /* EMACS_SEPARATE_PROCESS_GROUP () creates a separate process group for the
279 /* EMACS_SET_PROCESS_GROUP () sets our process group as specified. */
281 /* POSIX calls for setpgid(), so we use it if it's available.
282 Otherwise use setpgrp(), in USG or BSD flavor. Note that
283 on newer systems, setpgrp() has unwanted effects (e.g.
284 creating a new session), so we want to avoid its use
287 NOTE: On some older systems, we should consider using setpgrp2()
288 if it exists. This is sufficiently rare, though, that there
289 seems no point in autodetecting it. Currently dgux.h is the
290 only place where this has to be munged. */
292 #if defined (HAVE_SETPGID)
293 # define EMACS_SEPARATE_PROCESS_GROUP() setpgid (0, 0)
294 # define EMACS_SET_PROCESS_GROUP(pg) setpgid (0, pg)
296 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp ()
297 /* old (pre-SVR4) USG's don't provide any way to do this.
298 No big loss -- it just means that ^Z won't work right
299 if we're run from sh. */
300 # define EMACS_SET_PROCESS_GROUP(pg)
302 /* Under NeXTstep, a process group of 0 is not the same as specifying
303 your own process ID, so we go ahead and specify it explicitly. */
304 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp (0, getpid ())
305 # define EMACS_SET_PROCESS_GROUP(pg) setpgrp (0, pg)
308 /* --------------------------------------------------------- */
309 /* Manipulate a TTY's input/output processing parameters */
310 /* --------------------------------------------------------- */
312 /* struct emacs_tty is a structure used to hold the current tty
313 parameters. If the terminal has several structures describing its
314 state, for example a struct tchars, a struct sgttyb, a struct
315 tchars, a struct ltchars, and a struct pagechars, struct
316 emacs_tty should contain an element for each parameter struct
317 that Emacs may change.
319 emacs_get_tty (int FD, struct emacs_tty *P) stores the parameters
320 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
321 into an error we couldn't deal with.
323 emacs_set_tty (int FD, struct emacs_tty *P, int flushp)
324 sets the parameters of the tty on FD according to the contents of
325 *P. If flushp is non-zero, we discard queued input to be
326 written before making the change.
327 Return 0 if all went well, and -1 if anything failed.
329 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
330 expands tabs to spaces upon output; in that case, there is no
331 advantage to using tabs over spaces. */
333 /* For each tty parameter structure that Emacs might want to save and restore,
334 - include an element for it in this structure, and
335 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
340 /* There is always one of the following elements, so there is no need
341 for dummy get and set definitions. */
344 #else /* !HAVE_TCATTR */
347 #else /* !HAVE_TERMIO */
349 #endif /* !HAVE_TERMIO */
350 #endif /* !HAVE_TCATTR */
352 /* If we have TERMIOS, we don't need to do this - they're taken care of
353 by the tc*attr calls. */
356 struct ltchars ltchars;
357 #endif /* HAVE_LTCHARS */
360 struct tchars tchars;
362 #endif /* HAVE_TCHARS */
363 #endif /* HAVE_TERMIOS */
366 int emacs_get_tty(int fd, struct emacs_tty *settings);
367 int emacs_set_tty(int fd, struct emacs_tty *settings, int flushp);
369 /* --------------------------------------------------------- */
370 /* Define EMACS_TTY_TABS_OK */
371 /* --------------------------------------------------------- */
376 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
378 #define EMACS_TTY_TABS_OK(p) 1
381 #else /* not def HAVE_TERMIOS */
384 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
386 #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
387 #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS)
389 #endif /* not def HAVE_TERMIO */
390 #endif /* not def HAVE_TERMIOS */
392 #endif /* INCLUDED_systty_h_ */