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