Merge from gnus--devo--0
[emacs.git] / src / systty.h
blob4d9bd792a3cfb1646336dc3e730a438972dbe345
1 /* systty.h - System-dependent definitions for terminals.
2 Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 #ifdef HAVE_TERMIOS
21 #define HAVE_TCATTR
22 #endif
25 /* Include the proper files. */
26 #ifdef HAVE_TERMIO
27 #ifndef NO_TERMIO
28 #include <termio.h>
29 #endif /* not NO_TERMIO */
30 #ifndef INCLUDED_FCNTL
31 #define INCLUDED_FCNTL
32 #include <fcntl.h>
33 #endif
34 #else /* not HAVE_TERMIO */
35 #ifdef HAVE_TERMIOS
36 #if defined(_AIX) && defined(_I386)
37 #include <termios.h> /* termios.h needs to be before termio.h */
38 #include <termio.h>
39 #else /* not (_AIX && _I386) */
40 #ifndef NO_TERMIO
41 #include <termio.h>
42 #endif
43 #include <termios.h>
44 #endif /* not (_AIX && _I386) */
45 #define INCLUDED_FCNTL
46 #include <fcntl.h>
47 #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
48 #ifndef VMS
49 #ifndef DOS_NT
50 #include <sgtty.h>
51 #endif /* not DOS_NT */
52 #else /* VMS */
53 #include <descrip.h>
54 static struct iosb
56 short status;
57 short offset;
58 short termlen;
59 short term;
60 } input_iosb;
62 extern int waiting_for_ast;
63 extern int stop_input;
64 extern int input_ef;
65 extern int timer_ef;
66 extern int process_ef;
67 extern int input_eflist;
68 extern int timer_eflist;
70 static $DESCRIPTOR (input_dsc, "TT");
71 static int terminator_mask[2] = { 0, 0 };
73 static struct sensemode {
74 short status;
75 unsigned char xmit_baud;
76 unsigned char rcv_baud;
77 unsigned char crfill;
78 unsigned char lffill;
79 unsigned char parity;
80 unsigned char unused;
81 char class;
82 char type;
83 short scr_wid;
84 unsigned long tt_char : 24, scr_len : 8;
85 unsigned long tt2_char;
86 } sensemode_iosb;
87 #endif /* VMS */
88 #endif /* not HAVE_TERMIOS */
89 #endif /* not HAVE_TERMIO */
91 #ifdef __GNU_LIBRARY__
92 #include <sys/ioctl.h>
93 #include <termios.h>
94 #endif
96 #ifdef NEED_BSDTTY
97 #include <sys/bsdtty.h>
98 #endif
100 #if defined (HPUX) && defined (HAVE_PTYS)
101 #include <sys/ptyio.h>
102 #endif
104 #ifdef AIX
105 #include <sys/pty.h>
106 #endif /* AIX */
108 #if (defined (POSIX) || defined (NEED_UNISTD_H)) && defined (HAVE_UNISTD_H)
109 #include <unistd.h>
110 #endif
112 #ifdef SYSV_PTYS
113 #include <sys/types.h>
114 #include <sys/tty.h>
115 #include <sys/pty.h>
116 #endif
119 /* Special cases - inhibiting the use of certain features. */
121 #ifdef BROKEN_TIOCGETC
122 #undef TIOCGETC /* Avoid confusing some conditionals that test this. */
123 #endif
125 /* Allow m- file to inhibit use of FIONREAD. */
126 #ifdef BROKEN_FIONREAD
127 #undef FIONREAD
128 #undef ASYNC
129 #endif
131 /* Interrupt input is not used if there is no FIONREAD. */
132 #ifndef FIONREAD
133 #undef SIGIO
134 #endif
136 /* On TERMIOS systems, the tcmumbleattr calls take care of these
137 parameters, and it's a bad idea to use them (on AIX, it makes the
138 tty hang for a long time). */
139 #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
140 #define HAVE_LTCHARS
141 #endif
143 #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
144 #define HAVE_TCHARS
145 #endif
148 /* Try to establish the correct character to disable terminal functions
149 in a system-independent manner. Note that USG (at least) define
150 _POSIX_VDISABLE as 0! */
152 #ifdef _POSIX_VDISABLE
153 #define CDISABLE _POSIX_VDISABLE
154 #else /* not _POSIX_VDISABLE */
155 #ifdef CDEL
156 #undef CDISABLE
157 #define CDISABLE CDEL
158 #else /* not CDEL */
159 #define CDISABLE 255
160 #endif /* not CDEL */
161 #endif /* not _POSIX_VDISABLE */
163 /* Get the number of characters queued for output. */
165 /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
166 queued for output to the terminal FD in *SIZE, if FD is a tty.
167 Returns -1 if there was an error (i.e. FD is not a tty), 0
168 otherwise. */
169 #ifdef TIOCOUTQ
170 #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size)))
171 #endif
173 #ifdef HAVE_TERMIO
174 #ifdef TCOUTQ
175 #undef EMACS_OUTQSIZE
176 #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TCOUTQ, (size)))
177 #endif
178 #endif
181 /* Manipulate a terminal's current process group. */
183 /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current
184 controlling process group.
186 EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's
187 current process group. Return -1 if there is an error.
189 EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's
190 current process group to *PGID. Return -1 if there is an error. */
192 #ifdef HPUX
193 /* HPUX tty process group stuff doesn't work, says the anonymous voice
194 from the past. */
195 #else
196 #ifdef TIOCGPGRP
197 #define EMACS_HAVE_TTY_PGRP
198 #else
199 #ifdef HAVE_TERMIOS
200 #define EMACS_HAVE_TTY_PGRP
201 #endif
202 #endif
203 #endif
205 #ifdef EMACS_HAVE_TTY_PGRP
207 #if defined (HAVE_TERMIOS) && ! defined (BSD_TERMIOS)
209 #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp ((fd)))
210 #define EMACS_SET_TTY_PGRP(fd, pgid) (tcsetpgrp ((fd), *(pgid)))
212 #else
213 #ifdef TIOCSPGRP
215 #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid)))
216 #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid)))
218 #endif
219 #endif
221 #else
223 /* Just ignore this for now and hope for the best */
224 #define EMACS_GET_TTY_PGRP(fd, pgid) 0
225 #define EMACS_SET_TTY_PGRP(fd, pgif) 0
227 #endif
229 /* EMACS_GETPGRP (arg) returns the process group of the process. */
231 #if defined (GETPGRP_VOID)
232 # define EMACS_GETPGRP(x) getpgrp()
233 #else
234 # define EMACS_GETPGRP(x) getpgrp(x)
235 #endif /* !GETPGRP_VOID */
237 /* Manipulate a TTY's input/output processing parameters. */
239 /* struct emacs_tty is a structure used to hold the current tty
240 parameters. If the terminal has several structures describing its
241 state, for example a struct tchars, a struct sgttyb, a struct
242 tchars, a struct ltchars, and a struct pagechars, struct
243 emacs_tty should contain an element for each parameter struct
244 that Emacs may change.
246 EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the parameters
247 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
248 into an error we couldn't deal with.
250 EMACS_SET_TTY (int FD, struct emacs_tty *P, int flushp)
251 sets the parameters of the tty on FD according to the contents of
252 *P. If flushp is non-zero, we discard queued input to be
253 written before making the change.
254 Return 0 if all went well, and -1 if anything failed.
256 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false if the kernel
257 expands tabs to spaces upon output; in that case, there is no
258 advantage to using tabs over spaces. */
261 /* For each tty parameter structure that Emacs might want to save and restore,
262 - include an element for it in this structure, and
263 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
264 new members. */
266 struct emacs_tty {
268 /* There is always one of the following elements, so there is no need
269 for dummy get and set definitions. */
270 #ifdef HAVE_TCATTR
271 struct termios main;
272 #else
273 #ifdef HAVE_TERMIO
274 struct termio main;
275 #else
276 #ifdef VMS
277 struct sensemode main;
278 #else
279 #ifdef DOS_NT
280 int main;
281 #else /* not DOS_NT */
282 struct sgttyb main;
283 #endif /* not DOS_NT */
284 #endif
285 #endif
286 #endif
288 /* If we have TERMIOS, we don't need to do this - they're taken care of
289 by the tc*attr calls. */
290 #ifndef HAVE_TERMIOS
291 #ifdef HAVE_LTCHARS
292 struct ltchars ltchars;
293 #endif
295 #ifdef HAVE_TCHARS
296 struct tchars tchars;
297 int lmode;
298 #endif
299 #endif
302 /* Define EMACS_GET_TTY and EMACS_SET_TTY,
303 the macros for reading and setting parts of `struct emacs_tty'.
305 These got pretty unmanageable (huge macros are hard to debug), and
306 finally needed some code which couldn't be done as part of an
307 expression, so we moved them out to their own functions in sysdep.c. */
308 #define EMACS_GET_TTY(fd, p) (emacs_get_tty ((fd), (p)))
309 #define EMACS_SET_TTY(fd, p, waitp) (emacs_set_tty ((fd), (p), (waitp)))
310 #ifdef P_ /* Unfortunately this file is sometimes included before lisp.h */
311 extern int emacs_get_tty P_ ((int, struct emacs_tty *));
312 extern int emacs_set_tty P_ ((int, struct emacs_tty *, int));
313 #endif
316 /* Define EMACS_TTY_TABS_OK. */
318 #ifdef HAVE_TERMIOS
320 #ifdef TABDLY
321 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
322 #else
323 #define EMACS_TTY_TABS_OK(p) 1
324 #endif
326 #else /* not def HAVE_TERMIOS */
327 #ifdef HAVE_TERMIO
329 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
331 #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
332 #ifdef VMS
334 #define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0)
336 #else
338 #ifdef DOS_NT
339 #define EMACS_TTY_TABS_OK(p) 0
340 #else /* not DOS_NT */
341 #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS)
342 #endif /* not DOS_NT */
344 #endif /* not def VMS */
345 #endif /* not def HAVE_TERMIO */
346 #endif /* not def HAVE_TERMIOS */
348 /* arch-tag: cf4b90bc-be41-401c-be98-40619178a712
349 (do not change this comment) */