(Fstart_process): GCPRO some things.
[bpt/emacs.git] / src / systty.h
CommitLineData
a04c9535 1/* systty.h - System-dependent definitions for terminals.
c6c5df7f 2 Copyright (C) 1993 Free Software Foundation, Inc.
d0d6b7c5
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
2182d459
RS
20#ifdef HAVE_TERMIOS
21#define HAVE_TCATTR
22#endif
7f6d476f
RS
23
24/* If we defined these before and we are about to redefine them,
25 prevent alarming warnings. */
26#ifdef BSD_TERMIOS
27#undef NL0
28#undef NL1
29#undef CR0
30#undef CR1
31#undef CR2
32#undef CR3
33#undef TAB0
34#undef TAB1
35#undef TAB2
36#undef XTABS
37#undef BS0
38#undef BS1
39#undef FF0
40#undef FF1
41#undef ECHO
42#undef NOFLSH
43#undef TOSTOP
44#undef FLUSHO
45#undef PENDIN
46#endif
d0d6b7c5
JB
47\f
48/* Include the proper files. */
49#ifdef HAVE_TERMIO
0674a1f9
JB
50#ifdef __DGUX
51#include <sys/ioctl.h>
52#endif
d2d846a3 53#ifndef NO_TERMIO
d0d6b7c5 54#include <termio.h>
d2d846a3 55#endif /* not NO_TERMIO */
d0d6b7c5
JB
56#include <fcntl.h>
57#else
58#ifdef HAVE_TERMIOS
3580badc
RS
59#if defined(_AIX) && defined(_I386)
60#include <termios.h> /* termios.h needs to be before termio.h */
61#include <termio.h>
62#else
c62e9958 63#ifndef NO_TERMIO
d0d6b7c5 64#include <termio.h>
c62e9958 65#endif
d0d6b7c5 66#include <termios.h>
3580badc 67#endif /* _AIX && _I386 */
1aaaff21 68#include <fcntl.h>
d0d6b7c5
JB
69#else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
70#ifndef VMS
8e99c732 71#ifndef MSDOS
d0d6b7c5 72#include <sgtty.h>
8e99c732 73#endif
a04c9535
JB
74#else /* VMS */
75#include <descrip.h>
76static struct iosb
77{
78 short status;
79 short offset;
80 short termlen;
81 short term;
82} input_iosb;
83
84extern int waiting_for_ast;
85extern int stop_input;
210b2b4f 86#if 0 /* VAX C doeasn't understand initializing declarations */
a04c9535
JB
87extern int input_ef = 0;
88extern int timer_ef = 0;
89extern int process_ef = 0;
210b2b4f
JB
90#else
91extern int input_ef;
92extern int timer_ef;
93extern int process_ef;
94#endif
a04c9535
JB
95extern int input_eflist;
96extern int timer_eflist;
97
98static $DESCRIPTOR (input_dsc, "TT");
99static int terminator_mask[2] = { 0, 0 };
100
101static struct sensemode {
102 short status;
103 unsigned char xmit_baud;
104 unsigned char rcv_baud;
105 unsigned char crfill;
106 unsigned char lffill;
107 unsigned char parity;
108 unsigned char unused;
109 char class;
110 char type;
111 short scr_wid;
112 unsigned long tt_char : 24, scr_len : 8;
113 unsigned long tt2_char;
114} sensemode_iosb;
115#endif /* VMS */
d0d6b7c5
JB
116#endif /* not HAVE_TERMIOS */
117#endif /* not HAVE_TERMIO */
118
4746118a
JB
119#ifdef AIX
120/* Get files for keyboard remapping */
121#define HFNKEYS 2
122#include <sys/hft.h>
123#include <sys/devinfo.h>
124#endif
125
126/* Get rid of LLITOUT in 4.1, since it is said to stimulate kernel bugs. */
127#ifdef BSD4_1
128#undef LLITOUT
129#define LLITOUT 0
130#endif /* 4.1 */
131
132#ifdef NEED_BSDTTY
133#include <sys/bsdtty.h>
134#endif
135
136#if defined (HPUX) && defined (HAVE_PTYS)
137#include <sys/ptyio.h>
138#endif
139
140#ifdef AIX
141#include <sys/pty.h>
142#include <unistd.h>
9825c716 143#define UNISTD_H_INCLUDED
4746118a
JB
144#endif /* AIX */
145
5ab57b9f
RS
146#ifdef IRIX4
147/* Get _getpty prototype */
148#include <unistd.h>
9825c716
BF
149#define UNISTD_H_INCLUDED
150#endif
151
152#if defined (POSIX) && !defined (UNISTD_H_INCLUDED) && defined (HAVE_UNISTD_H)
153#include <unistd.h>
154#define UNISTD_H_INCLUDED
5ab57b9f
RS
155#endif
156
4746118a 157#ifdef SYSV_PTYS
8243aa4e 158#include <sys/types.h>
4746118a 159#include <sys/tty.h>
ffd56f97
JB
160#ifdef titan
161#include <sys/ttyhw.h>
162#include <sys/stream.h>
163#endif
372d3c2e 164#ifndef NO_PTY_H
4746118a
JB
165#include <sys/pty.h>
166#endif
372d3c2e 167#endif
4746118a
JB
168
169/* saka@pfu.fujitsu.co.JP writes:
170 FASYNC defined in this file. But, FASYNC don't working.
171 so no problem, because unrequest_sigio only need. */
172#if defined (pfa)
173#include <sys/file.h>
174#endif
175
d0d6b7c5
JB
176\f
177/* Special cases - inhibiting the use of certain features. */
178
179#ifdef APOLLO
180#undef TIOCSTART
181#endif
182
ffd56f97
JB
183#ifdef XENIX
184#undef TIOCGETC /* Avoid confusing some conditionals that test this. */
185#endif
186
d0d6b7c5
JB
187#ifdef BROKEN_TIOCGETC
188#undef TIOCGETC /* Avoid confusing some conditionals that test this. */
189#endif
190
191/* UNIPLUS systems may have FIONREAD. */
192#ifdef UNIPLUS
193#include <sys.ioctl.h>
194#endif
195
196/* Allow m- file to inhibit use of FIONREAD. */
197#ifdef BROKEN_FIONREAD
198#undef FIONREAD
199#undef ASYNC
200#endif
201
eb8c3be9 202/* Interrupt input is not used if there is no FIONREAD. */
d0d6b7c5
JB
203#ifndef FIONREAD
204#undef SIGIO
205#endif
206
50b8cf60
JB
207/* On TERMIOS systems, the tcmumbleattr calls take care of these
208 parameters, and it's a bad idea to use them (on AIX, it makes the
c39d651c 209 tty hang for a long time). */
50b8cf60
JB
210#if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
211#define HAVE_LTCHARS
212#endif
213
214#if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
215#define HAVE_TCHARS
216#endif
217
d0d6b7c5 218\f
2102829e
RS
219/* Try to establish the correct character to disable terminal functions
220 in a system-independent manner. Note that USG (at least) define
221 _POSIX_VDISABLE as 0! */
222
223#ifdef _POSIX_VDISABLE
224#define CDISABLE _POSIX_VDISABLE
225#else /* not _POSIX_VDISABLE */
226#ifdef CDEL
d04e8e46 227#undef CDISABLE
2102829e
RS
228#define CDISABLE CDEL
229#else /* not CDEL */
230#define CDISABLE 255
231#endif /* not CDEL */
232#endif /* not _POSIX_VDISABLE */
233\f
d0d6b7c5
JB
234/* Get the number of characters queued for output. */
235
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
239 otherwise. */
240#ifdef TIOCOUTQ
241#define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size)))
242#endif
243
244#ifdef HAVE_TERMIO
245#ifdef TCOUTQ
246#undef EMACS_OUTQSIZE
247#define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TCOUTQ, (size)))
248#endif
249#endif
250
251\f
252/* Manipulate a terminal's current process group. */
253
254/* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current
255 controlling process group.
256
257 EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's
258 current process group. Return -1 if there is an error.
259
260 EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's
261 current process group to *PGID. Return -1 if there is an error. */
262
ffd56f97
JB
263#ifdef HPUX
264/* HPUX tty process group stuff doesn't work, says the anonymous voice
265 from the past. */
266#else
d0d6b7c5
JB
267#ifdef TIOCGPGRP
268#define EMACS_HAVE_TTY_PGRP
269#else
270#ifdef HAVE_TERMIOS
271#define EMACS_HAVE_TTY_PGRP
272#endif
273#endif
ffd56f97 274#endif
d0d6b7c5
JB
275
276#ifdef EMACS_HAVE_TTY_PGRP
277
75bb6750 278#if defined (HAVE_TERMIOS) && ! defined (BSD_TERMIOS)
d0d6b7c5
JB
279
280#define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp ((fd)))
161aa2f8 281#define EMACS_SET_TTY_PGRP(fd, pgid) (tcsetpgrp ((fd), *(pgid)))
d0d6b7c5
JB
282
283#else
284#ifdef TIOCSPGRP
285
286#define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid)))
287#define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid)))
288
289#endif
290#endif
291
292#else
293
294/* Just ignore this for now and hope for the best */
295#define EMACS_GET_TTY_PGRP(fd, pgid) 0
ef15f270 296#define EMACS_SET_TTY_PGRP(fd, pgif) 0
d0d6b7c5
JB
297
298#endif
299
727b007c
RS
300/* EMACS_GETPGRP (arg) returns the process group of the terminal. */
301
302#if defined (USG) && !defined (GETPGRP_NEEDS_ARG)
303# if !defined (GETPGRP_NO_ARG)
304# define GETPGRP_NO_ARG
305# endif
306#endif
307
308#if defined (GETPGRP_NO_ARG)
309# define EMACS_GETPGRP(x) getpgrp()
310#else
311# define EMACS_GETPGRP(x) getpgrp(x)
312#endif /* !GETPGRP_NO_ARG */
d0d6b7c5
JB
313\f
314/* Manipulate a TTY's input/output processing parameters. */
315
316/* struct emacs_tty is a structure used to hold the current tty
317 parameters. If the terminal has several structures describing its
318 state, for example a struct tchars, a struct sgttyb, a struct
319 tchars, a struct ltchars, and a struct pagechars, struct
320 emacs_tty should contain an element for each parameter struct
321 that Emacs may change.
322
1334b321
JB
323 EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the parameters
324 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
325 into an error we couldn't deal with.
d0d6b7c5
JB
326
327 EMACS_SET_TTY (int FD, struct emacs_tty *P, int waitp)
328 sets the parameters of the tty on FD according to the contents of
329 *P. If waitp is non-zero, we wait for all queued output to be
330 written before making the change; otherwise, we forget any queued
331 input and make the change immediately.
1334b321 332 Return 0 if all went well, and -1 if anything failed.
d0d6b7c5
JB
333
334 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
335 expands tabs to spaces upon output; in that case, there is no
336 advantage to using tabs over spaces. */
337
338
d0d6b7c5 339/* For each tty parameter structure that Emacs might want to save and restore,
1334b321
JB
340 - include an element for it in this structure, and
341 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
342 new members. */
d0d6b7c5
JB
343
344struct emacs_tty {
345
346/* There is always one of the following elements, so there is no need
347 for dummy get and set definitions. */
2182d459 348#ifdef HAVE_TCATTR
d0d6b7c5
JB
349 struct termios main;
350#else
351#ifdef HAVE_TERMIO
352 struct termio main;
353#else
354#ifdef VMS
355 struct sensemode main;
8e99c732
RS
356#else
357#ifdef MSDOS
358 int main;
d0d6b7c5
JB
359#else
360 struct sgttyb main;
361#endif
362#endif
363#endif
8e99c732 364#endif
50b8cf60
JB
365
366/* If we have TERMIOS, we don't need to do this - they're taken care of
367 by the tc*attr calls. */
368#ifndef HAVE_TERMIOS
369#ifdef HAVE_LTCHARS
2182d459
RS
370 struct ltchars ltchars;
371#endif
50b8cf60
JB
372
373#ifdef HAVE_TCHARS
2182d459
RS
374 struct tchars tchars;
375 int lmode;
d0d6b7c5 376#endif
50b8cf60 377#endif
2182d459
RS
378};
379\f
380/* Define EMACS_GET_TTY and EMACS_SET_TTY,
c2e4f49a 381 the macros for reading and setting parts of `struct emacs_tty'.
d0d6b7c5 382
c2e4f49a
JB
383 These got pretty unmanageable (huge macros are hard to debug), and
384 finally needed some code which couldn't be done as part of an
385 expression, so we moved them out to their own functions in sysdep.c. */
386#define EMACS_GET_TTY(fd, p) (emacs_get_tty ((fd), (p)))
387#define EMACS_SET_TTY(fd, p, waitp) (emacs_set_tty ((fd), (p), (waitp)))
d0d6b7c5 388
2182d459
RS
389\f
390/* Define EMACS_TTY_TABS_OK. */
d0d6b7c5
JB
391
392#ifdef HAVE_TERMIOS
393
c7040669 394#ifdef TABDLY
d0d6b7c5 395#define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
c7040669
RS
396#else
397#define EMACS_TTY_TABS_OK(p) 1
398#endif
d0d6b7c5
JB
399
400#else /* not def HAVE_TERMIOS */
401#ifdef HAVE_TERMIO
402
403#define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
404
405#else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
406#ifdef VMS
407
408#define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0)
409
410#else
411
8e99c732
RS
412#ifdef MSDOS
413#define EMACS_TTY_TABS_OK(p) 0
414#else /* not MSDOS */
d0d6b7c5 415#define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS)
8e99c732 416#endif /* not MSDOS */
d0d6b7c5
JB
417
418#endif /* not def VMS */
419#endif /* not def HAVE_TERMIO */
420#endif /* not def HAVE_TERMIOS */