Commit | Line | Data |
---|---|---|
a04c9535 | 1 | /* systty.h - System-dependent definitions for terminals. |
429ab54e | 2 | Copyright (C) 1993, 1994, 2001, 2002, 2003, 2004, |
8cabe764 | 3 | 2005, 2006, 2007, 2008 Free Software Foundation, Inc. |
d0d6b7c5 JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
b9b1cc14 | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
d0d6b7c5 | 8 | it under the terms of the GNU General Public License as published by |
b9b1cc14 GM |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. | |
d0d6b7c5 JB |
11 | |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
b9b1cc14 | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
d0d6b7c5 | 19 | |
2182d459 RS |
20 | #ifdef HAVE_TERMIOS |
21 | #define HAVE_TCATTR | |
22 | #endif | |
7f6d476f | 23 | |
d0d6b7c5 JB |
24 | \f |
25 | /* Include the proper files. */ | |
26 | #ifdef HAVE_TERMIO | |
d2d846a3 | 27 | #ifndef NO_TERMIO |
d0d6b7c5 | 28 | #include <termio.h> |
d2d846a3 | 29 | #endif /* not NO_TERMIO */ |
92ea836d | 30 | #ifndef INCLUDED_FCNTL |
b65e3dd7 | 31 | #define INCLUDED_FCNTL |
d0d6b7c5 | 32 | #include <fcntl.h> |
92ea836d RS |
33 | #endif |
34 | #else /* not HAVE_TERMIO */ | |
d0d6b7c5 | 35 | #ifdef HAVE_TERMIOS |
3580badc RS |
36 | #if defined(_AIX) && defined(_I386) |
37 | #include <termios.h> /* termios.h needs to be before termio.h */ | |
38 | #include <termio.h> | |
ab9ba9ea | 39 | #else /* not (_AIX && _I386) */ |
c62e9958 | 40 | #ifndef NO_TERMIO |
d0d6b7c5 | 41 | #include <termio.h> |
c62e9958 | 42 | #endif |
d0d6b7c5 | 43 | #include <termios.h> |
ab9ba9ea | 44 | #endif /* not (_AIX && _I386) */ |
b65e3dd7 | 45 | #define INCLUDED_FCNTL |
1aaaff21 | 46 | #include <fcntl.h> |
d0d6b7c5 JB |
47 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ |
48 | #ifndef VMS | |
101adcb5 | 49 | #ifndef DOS_NT |
d0d6b7c5 | 50 | #include <sgtty.h> |
101adcb5 | 51 | #endif /* not DOS_NT */ |
a04c9535 JB |
52 | #else /* VMS */ |
53 | #include <descrip.h> | |
54 | static struct iosb | |
55 | { | |
56 | short status; | |
57 | short offset; | |
58 | short termlen; | |
59 | short term; | |
60 | } input_iosb; | |
61 | ||
62 | extern int waiting_for_ast; | |
63 | extern int stop_input; | |
210b2b4f JB |
64 | extern int input_ef; |
65 | extern int timer_ef; | |
66 | extern int process_ef; | |
a04c9535 JB |
67 | extern int input_eflist; |
68 | extern int timer_eflist; | |
69 | ||
70 | static $DESCRIPTOR (input_dsc, "TT"); | |
71 | static int terminator_mask[2] = { 0, 0 }; | |
72 | ||
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 */ | |
d0d6b7c5 JB |
88 | #endif /* not HAVE_TERMIOS */ |
89 | #endif /* not HAVE_TERMIO */ | |
90 | ||
c9b67b7b | 91 | #ifdef __GNU_LIBRARY__ |
c3ff76c4 | 92 | #include <sys/ioctl.h> |
c9b67b7b RM |
93 | #include <termios.h> |
94 | #endif | |
95 | ||
4746118a JB |
96 | #ifdef NEED_BSDTTY |
97 | #include <sys/bsdtty.h> | |
177c0ea7 | 98 | #endif |
4746118a JB |
99 | |
100 | #if defined (HPUX) && defined (HAVE_PTYS) | |
101 | #include <sys/ptyio.h> | |
102 | #endif | |
378ac314 | 103 | |
4746118a JB |
104 | #ifdef AIX |
105 | #include <sys/pty.h> | |
4746118a JB |
106 | #endif /* AIX */ |
107 | ||
378ac314 | 108 | #if (defined (POSIX) || defined (NEED_UNISTD_H)) && defined (HAVE_UNISTD_H) |
9825c716 | 109 | #include <unistd.h> |
5ab57b9f RS |
110 | #endif |
111 | ||
d0d6b7c5 JB |
112 | \f |
113 | /* Special cases - inhibiting the use of certain features. */ | |
114 | ||
d0d6b7c5 JB |
115 | /* Allow m- file to inhibit use of FIONREAD. */ |
116 | #ifdef BROKEN_FIONREAD | |
117 | #undef FIONREAD | |
118 | #undef ASYNC | |
119 | #endif | |
120 | ||
eb8c3be9 | 121 | /* Interrupt input is not used if there is no FIONREAD. */ |
d0d6b7c5 JB |
122 | #ifndef FIONREAD |
123 | #undef SIGIO | |
124 | #endif | |
125 | ||
50b8cf60 JB |
126 | /* On TERMIOS systems, the tcmumbleattr calls take care of these |
127 | parameters, and it's a bad idea to use them (on AIX, it makes the | |
c39d651c | 128 | tty hang for a long time). */ |
50b8cf60 JB |
129 | #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS) |
130 | #define HAVE_LTCHARS | |
131 | #endif | |
132 | ||
133 | #if defined (TIOCGETC) && !defined (HAVE_TERMIOS) | |
134 | #define HAVE_TCHARS | |
135 | #endif | |
136 | ||
d0d6b7c5 | 137 | \f |
2102829e RS |
138 | /* Try to establish the correct character to disable terminal functions |
139 | in a system-independent manner. Note that USG (at least) define | |
140 | _POSIX_VDISABLE as 0! */ | |
141 | ||
142 | #ifdef _POSIX_VDISABLE | |
143 | #define CDISABLE _POSIX_VDISABLE | |
144 | #else /* not _POSIX_VDISABLE */ | |
145 | #ifdef CDEL | |
d04e8e46 | 146 | #undef CDISABLE |
2102829e RS |
147 | #define CDISABLE CDEL |
148 | #else /* not CDEL */ | |
149 | #define CDISABLE 255 | |
150 | #endif /* not CDEL */ | |
151 | #endif /* not _POSIX_VDISABLE */ | |
152 | \f | |
d0d6b7c5 JB |
153 | /* Get the number of characters queued for output. */ |
154 | ||
155 | /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters | |
156 | queued for output to the terminal FD in *SIZE, if FD is a tty. | |
157 | Returns -1 if there was an error (i.e. FD is not a tty), 0 | |
158 | otherwise. */ | |
159 | #ifdef TIOCOUTQ | |
160 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size))) | |
161 | #endif | |
162 | ||
163 | #ifdef HAVE_TERMIO | |
164 | #ifdef TCOUTQ | |
165 | #undef EMACS_OUTQSIZE | |
166 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TCOUTQ, (size))) | |
167 | #endif | |
168 | #endif | |
169 | ||
170 | \f | |
171 | /* Manipulate a terminal's current process group. */ | |
172 | ||
173 | /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current | |
174 | controlling process group. | |
175 | ||
176 | EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's | |
177 | current process group. Return -1 if there is an error. | |
178 | ||
179 | EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's | |
180 | current process group to *PGID. Return -1 if there is an error. */ | |
181 | ||
ffd56f97 JB |
182 | #ifdef HPUX |
183 | /* HPUX tty process group stuff doesn't work, says the anonymous voice | |
184 | from the past. */ | |
185 | #else | |
d0d6b7c5 JB |
186 | #ifdef TIOCGPGRP |
187 | #define EMACS_HAVE_TTY_PGRP | |
188 | #else | |
189 | #ifdef HAVE_TERMIOS | |
190 | #define EMACS_HAVE_TTY_PGRP | |
191 | #endif | |
192 | #endif | |
ffd56f97 | 193 | #endif |
d0d6b7c5 JB |
194 | |
195 | #ifdef EMACS_HAVE_TTY_PGRP | |
196 | ||
75bb6750 | 197 | #if defined (HAVE_TERMIOS) && ! defined (BSD_TERMIOS) |
d0d6b7c5 JB |
198 | |
199 | #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp ((fd))) | |
161aa2f8 | 200 | #define EMACS_SET_TTY_PGRP(fd, pgid) (tcsetpgrp ((fd), *(pgid))) |
d0d6b7c5 JB |
201 | |
202 | #else | |
203 | #ifdef TIOCSPGRP | |
204 | ||
205 | #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid))) | |
206 | #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid))) | |
207 | ||
208 | #endif | |
209 | #endif | |
210 | ||
211 | #else | |
212 | ||
213 | /* Just ignore this for now and hope for the best */ | |
214 | #define EMACS_GET_TTY_PGRP(fd, pgid) 0 | |
ef15f270 | 215 | #define EMACS_SET_TTY_PGRP(fd, pgif) 0 |
d0d6b7c5 JB |
216 | |
217 | #endif | |
218 | ||
281bbdfb | 219 | /* EMACS_GETPGRP (arg) returns the process group of the process. */ |
727b007c | 220 | |
f7ff70e8 | 221 | #if defined (GETPGRP_VOID) |
727b007c RS |
222 | # define EMACS_GETPGRP(x) getpgrp() |
223 | #else | |
224 | # define EMACS_GETPGRP(x) getpgrp(x) | |
f7ff70e8 | 225 | #endif /* !GETPGRP_VOID */ |
d0d6b7c5 JB |
226 | \f |
227 | /* Manipulate a TTY's input/output processing parameters. */ | |
228 | ||
229 | /* struct emacs_tty is a structure used to hold the current tty | |
230 | parameters. If the terminal has several structures describing its | |
231 | state, for example a struct tchars, a struct sgttyb, a struct | |
232 | tchars, a struct ltchars, and a struct pagechars, struct | |
233 | emacs_tty should contain an element for each parameter struct | |
234 | that Emacs may change. | |
235 | ||
1334b321 JB |
236 | EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the parameters |
237 | of the tty on FD in *P. Return zero if all's well, or -1 if we ran | |
238 | into an error we couldn't deal with. | |
d0d6b7c5 | 239 | |
1bf61ff9 | 240 | EMACS_SET_TTY (int FD, struct emacs_tty *P, int flushp) |
d0d6b7c5 | 241 | sets the parameters of the tty on FD according to the contents of |
1bf61ff9 RS |
242 | *P. If flushp is non-zero, we discard queued input to be |
243 | written before making the change. | |
1334b321 | 244 | Return 0 if all went well, and -1 if anything failed. |
d0d6b7c5 | 245 | |
e0f24100 | 246 | EMACS_TTY_TABS_OK (struct emacs_tty *P) is false if the kernel |
d0d6b7c5 JB |
247 | expands tabs to spaces upon output; in that case, there is no |
248 | advantage to using tabs over spaces. */ | |
249 | ||
250 | ||
d0d6b7c5 | 251 | /* For each tty parameter structure that Emacs might want to save and restore, |
1334b321 JB |
252 | - include an element for it in this structure, and |
253 | - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the | |
254 | new members. */ | |
d0d6b7c5 JB |
255 | |
256 | struct emacs_tty { | |
257 | ||
258 | /* There is always one of the following elements, so there is no need | |
259 | for dummy get and set definitions. */ | |
2182d459 | 260 | #ifdef HAVE_TCATTR |
d0d6b7c5 JB |
261 | struct termios main; |
262 | #else | |
263 | #ifdef HAVE_TERMIO | |
264 | struct termio main; | |
265 | #else | |
266 | #ifdef VMS | |
267 | struct sensemode main; | |
8e99c732 | 268 | #else |
101adcb5 | 269 | #ifdef DOS_NT |
8e99c732 | 270 | int main; |
101adcb5 | 271 | #else /* not DOS_NT */ |
d0d6b7c5 | 272 | struct sgttyb main; |
101adcb5 | 273 | #endif /* not DOS_NT */ |
d0d6b7c5 JB |
274 | #endif |
275 | #endif | |
8e99c732 | 276 | #endif |
50b8cf60 JB |
277 | |
278 | /* If we have TERMIOS, we don't need to do this - they're taken care of | |
279 | by the tc*attr calls. */ | |
280 | #ifndef HAVE_TERMIOS | |
281 | #ifdef HAVE_LTCHARS | |
2182d459 RS |
282 | struct ltchars ltchars; |
283 | #endif | |
50b8cf60 JB |
284 | |
285 | #ifdef HAVE_TCHARS | |
2182d459 RS |
286 | struct tchars tchars; |
287 | int lmode; | |
d0d6b7c5 | 288 | #endif |
50b8cf60 | 289 | #endif |
2182d459 RS |
290 | }; |
291 | \f | |
292 | /* Define EMACS_GET_TTY and EMACS_SET_TTY, | |
c2e4f49a | 293 | the macros for reading and setting parts of `struct emacs_tty'. |
d0d6b7c5 | 294 | |
c2e4f49a JB |
295 | These got pretty unmanageable (huge macros are hard to debug), and |
296 | finally needed some code which couldn't be done as part of an | |
297 | expression, so we moved them out to their own functions in sysdep.c. */ | |
298 | #define EMACS_GET_TTY(fd, p) (emacs_get_tty ((fd), (p))) | |
299 | #define EMACS_SET_TTY(fd, p, waitp) (emacs_set_tty ((fd), (p), (waitp))) | |
4c571d09 AS |
300 | #ifdef P_ /* Unfortunately this file is sometimes included before lisp.h */ |
301 | extern int emacs_get_tty P_ ((int, struct emacs_tty *)); | |
302 | extern int emacs_set_tty P_ ((int, struct emacs_tty *, int)); | |
303 | #endif | |
d0d6b7c5 | 304 | |
2182d459 RS |
305 | \f |
306 | /* Define EMACS_TTY_TABS_OK. */ | |
d0d6b7c5 JB |
307 | |
308 | #ifdef HAVE_TERMIOS | |
309 | ||
c7040669 | 310 | #ifdef TABDLY |
d0d6b7c5 | 311 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) |
c7040669 RS |
312 | #else |
313 | #define EMACS_TTY_TABS_OK(p) 1 | |
314 | #endif | |
d0d6b7c5 JB |
315 | |
316 | #else /* not def HAVE_TERMIOS */ | |
317 | #ifdef HAVE_TERMIO | |
318 | ||
319 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) | |
320 | ||
321 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ | |
322 | #ifdef VMS | |
323 | ||
324 | #define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0) | |
325 | ||
326 | #else | |
327 | ||
101adcb5 | 328 | #ifdef DOS_NT |
8e99c732 | 329 | #define EMACS_TTY_TABS_OK(p) 0 |
101adcb5 | 330 | #else /* not DOS_NT */ |
d0d6b7c5 | 331 | #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS) |
101adcb5 | 332 | #endif /* not DOS_NT */ |
d0d6b7c5 JB |
333 | |
334 | #endif /* not def VMS */ | |
335 | #endif /* not def HAVE_TERMIO */ | |
336 | #endif /* not def HAVE_TERMIOS */ | |
ab5796a9 MB |
337 | |
338 | /* arch-tag: cf4b90bc-be41-401c-be98-40619178a712 | |
339 | (do not change this comment) */ |