Commit | Line | Data |
---|---|---|
a04c9535 | 1 | /* systty.h - System-dependent definitions for terminals. |
d0d6b7c5 JB |
2 | Copyright (C) 1992 Free Software Foundation, Inc. |
3 | ||
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs 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 1, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU Emacs 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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | \f | |
21 | /* Include the proper files. */ | |
22 | #ifdef HAVE_TERMIO | |
23 | #include <termio.h> | |
24 | #include <fcntl.h> | |
25 | #else | |
26 | #ifdef HAVE_TERMIOS | |
27 | #include <termio.h> | |
28 | #include <termios.h> | |
1aaaff21 | 29 | #include <fcntl.h> |
d0d6b7c5 JB |
30 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ |
31 | #ifndef VMS | |
32 | #include <sgtty.h> | |
a04c9535 JB |
33 | #else /* VMS */ |
34 | #include <descrip.h> | |
35 | static struct iosb | |
36 | { | |
37 | short status; | |
38 | short offset; | |
39 | short termlen; | |
40 | short term; | |
41 | } input_iosb; | |
42 | ||
43 | extern int waiting_for_ast; | |
44 | extern int stop_input; | |
45 | extern int input_ef = 0; | |
46 | extern int timer_ef = 0; | |
47 | extern int process_ef = 0; | |
48 | extern int input_eflist; | |
49 | extern int timer_eflist; | |
50 | ||
51 | static $DESCRIPTOR (input_dsc, "TT"); | |
52 | static int terminator_mask[2] = { 0, 0 }; | |
53 | ||
54 | static struct sensemode { | |
55 | short status; | |
56 | unsigned char xmit_baud; | |
57 | unsigned char rcv_baud; | |
58 | unsigned char crfill; | |
59 | unsigned char lffill; | |
60 | unsigned char parity; | |
61 | unsigned char unused; | |
62 | char class; | |
63 | char type; | |
64 | short scr_wid; | |
65 | unsigned long tt_char : 24, scr_len : 8; | |
66 | unsigned long tt2_char; | |
67 | } sensemode_iosb; | |
68 | #endif /* VMS */ | |
d0d6b7c5 JB |
69 | #endif /* not HAVE_TERMIOS */ |
70 | #endif /* not HAVE_TERMIO */ | |
71 | ||
4746118a JB |
72 | #ifdef AIX |
73 | /* Get files for keyboard remapping */ | |
74 | #define HFNKEYS 2 | |
75 | #include <sys/hft.h> | |
76 | #include <sys/devinfo.h> | |
77 | #endif | |
78 | ||
79 | /* Get rid of LLITOUT in 4.1, since it is said to stimulate kernel bugs. */ | |
80 | #ifdef BSD4_1 | |
81 | #undef LLITOUT | |
82 | #define LLITOUT 0 | |
83 | #endif /* 4.1 */ | |
84 | ||
85 | #ifdef NEED_BSDTTY | |
86 | #include <sys/bsdtty.h> | |
87 | #endif | |
88 | ||
89 | #if defined (HPUX) && defined (HAVE_PTYS) | |
90 | #include <sys/ptyio.h> | |
91 | #endif | |
92 | ||
93 | #ifdef AIX | |
94 | #include <sys/pty.h> | |
95 | #include <unistd.h> | |
96 | #endif /* AIX */ | |
97 | ||
98 | #ifdef SYSV_PTYS | |
99 | #include <sys/tty.h> | |
ffd56f97 JB |
100 | #ifdef titan |
101 | #include <sys/ttyhw.h> | |
102 | #include <sys/stream.h> | |
103 | #endif | |
4746118a JB |
104 | #include <sys/pty.h> |
105 | #endif | |
106 | ||
107 | /* saka@pfu.fujitsu.co.JP writes: | |
108 | FASYNC defined in this file. But, FASYNC don't working. | |
109 | so no problem, because unrequest_sigio only need. */ | |
110 | #if defined (pfa) | |
111 | #include <sys/file.h> | |
112 | #endif | |
113 | ||
d0d6b7c5 JB |
114 | \f |
115 | /* Special cases - inhibiting the use of certain features. */ | |
116 | ||
117 | #ifdef APOLLO | |
118 | #undef TIOCSTART | |
119 | #endif | |
120 | ||
ffd56f97 JB |
121 | #ifdef XENIX |
122 | #undef TIOCGETC /* Avoid confusing some conditionals that test this. */ | |
123 | #endif | |
124 | ||
d0d6b7c5 JB |
125 | #ifdef BROKEN_TIOCGETC |
126 | #undef TIOCGETC /* Avoid confusing some conditionals that test this. */ | |
127 | #endif | |
128 | ||
129 | /* UNIPLUS systems may have FIONREAD. */ | |
130 | #ifdef UNIPLUS | |
131 | #include <sys.ioctl.h> | |
132 | #endif | |
133 | ||
134 | /* Allow m- file to inhibit use of FIONREAD. */ | |
135 | #ifdef BROKEN_FIONREAD | |
136 | #undef FIONREAD | |
137 | #undef ASYNC | |
138 | #endif | |
139 | ||
140 | /* Interupt input is not used if there is no FIONREAD. */ | |
141 | #ifndef FIONREAD | |
142 | #undef SIGIO | |
143 | #endif | |
144 | ||
145 | \f | |
2102829e RS |
146 | /* Try to establish the correct character to disable terminal functions |
147 | in a system-independent manner. Note that USG (at least) define | |
148 | _POSIX_VDISABLE as 0! */ | |
149 | ||
150 | #ifdef _POSIX_VDISABLE | |
151 | #define CDISABLE _POSIX_VDISABLE | |
152 | #else /* not _POSIX_VDISABLE */ | |
153 | #ifdef CDEL | |
154 | #define CDISABLE CDEL | |
155 | #else /* not CDEL */ | |
156 | #define CDISABLE 255 | |
157 | #endif /* not CDEL */ | |
158 | #endif /* not _POSIX_VDISABLE */ | |
159 | \f | |
d0d6b7c5 JB |
160 | /* Get the number of characters queued for output. */ |
161 | ||
162 | /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters | |
163 | queued for output to the terminal FD in *SIZE, if FD is a tty. | |
164 | Returns -1 if there was an error (i.e. FD is not a tty), 0 | |
165 | otherwise. */ | |
166 | #ifdef TIOCOUTQ | |
167 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size))) | |
168 | #endif | |
169 | ||
170 | #ifdef HAVE_TERMIO | |
171 | #ifdef TCOUTQ | |
172 | #undef EMACS_OUTQSIZE | |
173 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TCOUTQ, (size))) | |
174 | #endif | |
175 | #endif | |
176 | ||
177 | \f | |
178 | /* Manipulate a terminal's current process group. */ | |
179 | ||
180 | /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current | |
181 | controlling process group. | |
182 | ||
183 | EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's | |
184 | current process group. Return -1 if there is an error. | |
185 | ||
186 | EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's | |
187 | current process group to *PGID. Return -1 if there is an error. */ | |
188 | ||
ffd56f97 JB |
189 | #ifdef HPUX |
190 | /* HPUX tty process group stuff doesn't work, says the anonymous voice | |
191 | from the past. */ | |
192 | #else | |
d0d6b7c5 JB |
193 | #ifdef TIOCGPGRP |
194 | #define EMACS_HAVE_TTY_PGRP | |
195 | #else | |
196 | #ifdef HAVE_TERMIOS | |
197 | #define EMACS_HAVE_TTY_PGRP | |
198 | #endif | |
199 | #endif | |
ffd56f97 | 200 | #endif |
d0d6b7c5 JB |
201 | |
202 | #ifdef EMACS_HAVE_TTY_PGRP | |
203 | ||
204 | #ifdef HAVE_TERMIOS | |
205 | ||
206 | #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp ((fd))) | |
207 | #define EMACS_SET_TTY_PGRP(fd, pgid) (*(pgid) = tcsetpgrp ((fd))) | |
208 | ||
209 | #else | |
210 | #ifdef TIOCSPGRP | |
211 | ||
212 | #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid))) | |
213 | #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid))) | |
214 | ||
215 | #endif | |
216 | #endif | |
217 | ||
218 | #else | |
219 | ||
220 | /* Just ignore this for now and hope for the best */ | |
221 | #define EMACS_GET_TTY_PGRP(fd, pgid) 0 | |
ef15f270 | 222 | #define EMACS_SET_TTY_PGRP(fd, pgif) 0 |
d0d6b7c5 JB |
223 | |
224 | #endif | |
225 | ||
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 | ||
236 | EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the | |
237 | parameters of the tty on FD in *P. | |
238 | ||
239 | EMACS_SET_TTY (int FD, struct emacs_tty *P, int waitp) | |
240 | sets the parameters of the tty on FD according to the contents of | |
241 | *P. If waitp is non-zero, we wait for all queued output to be | |
242 | written before making the change; otherwise, we forget any queued | |
243 | input and make the change immediately. | |
244 | ||
245 | EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel | |
246 | expands tabs to spaces upon output; in that case, there is no | |
247 | advantage to using tabs over spaces. */ | |
248 | ||
249 | ||
250 | ||
251 | /* For each tty parameter structure that Emacs might want to save and restore, | |
252 | - include an element for it in this structure, | |
253 | - define a pair of numbered macros to get and set it and return | |
254 | true iff the call succeeded, | |
255 | - give alternative definitions for when the component is not implemented | |
256 | which always succeed, and | |
257 | - extend the definition of EMACS_{GET,SET}_TTY_CHARS to include the | |
258 | new macros. */ | |
259 | ||
260 | struct emacs_tty { | |
261 | ||
262 | /* There is always one of the following elements, so there is no need | |
263 | for dummy get and set definitions. */ | |
264 | #ifdef HAVE_TERMIOS | |
265 | struct termios main; | |
266 | #else | |
267 | #ifdef HAVE_TERMIO | |
268 | struct termio main; | |
269 | #else | |
270 | #ifdef VMS | |
271 | struct sensemode main; | |
272 | #else | |
273 | struct sgttyb main; | |
274 | #endif | |
275 | #endif | |
276 | #endif | |
277 | ||
278 | #ifdef HAVE_TERMIOS | |
279 | #define HAVE_TCATTR | |
280 | #endif | |
281 | ||
282 | #ifdef HAVE_TCATTR | |
283 | ||
284 | #define EMACS_GET_TTY_1(fd, p) (tcgetattr ((fd), &(p)->main) != -1) | |
285 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
286 | (tcsetattr ((fd), (waitp) ? TCSAFLUSH : TCSADRAIN, &(p)->main) != -1) | |
287 | ||
4746118a JB |
288 | #else |
289 | #ifdef HAVE_TERMIO | |
290 | ||
291 | #define EMACS_GET_TTY_1(fd, p) (ioctl ((fd), TCGETA, &(p)->main) != -1) | |
292 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
293 | (ioctl ((fd), (waitp) ? TCSETAW : TCSETAF, &(p)->main) != -1) | |
294 | ||
d0d6b7c5 JB |
295 | #else |
296 | #ifdef VMS | |
297 | ||
298 | /* These definitions will really only work in sysdep.c, because of their | |
299 | use of input_iosb. I don't know enough about VMS QIO to fix this. */ | |
a04c9535 JB |
300 | #define EMACS_GET_TTY_1(fd, p) \ |
301 | (1 & SYS$QIOW (0, (fd), IO$_SENSEMODE, (p), 0, 0, \ | |
302 | &(p)->main.class, 12, 0, 0, 0, 0)) | |
303 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
304 | (1 & SYS$QIOW (0, (fd), IO$_SETMODE, &input_iosb, 0, 0, \ | |
305 | &(p)->main.class, 12, 0, 0, 0, 0)) | |
d0d6b7c5 JB |
306 | |
307 | #else | |
308 | ||
309 | #define EMACS_GET_TTY_1(fd, p) (ioctl ((fd), TIOCGETP, &(p)->main) != -1) | |
310 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
311 | (ioctl ((fd), (waitp) ? TIOCSETP : TIOCSETN, &(p)->main) != -1) | |
312 | ||
313 | #endif | |
314 | #endif | |
4746118a | 315 | #endif |
d0d6b7c5 JB |
316 | |
317 | #ifdef TIOCGLTC | |
318 | struct ltchars ltchars; | |
319 | #define EMACS_GET_TTY_2(fd, p) \ | |
320 | (ioctl ((fd), TIOCGLTC, &(p)->ltchars) != -1) | |
321 | #define EMACS_SET_TTY_2(fd, p, waitp) \ | |
322 | (ioctl ((fd), TIOCSLTC, &(p)->ltchars) != -1) | |
323 | #else | |
324 | #define EMACS_GET_TTY_2(fd, p) 1 | |
325 | #define EMACS_SET_TTY_2(fd, p, waitp) 1 | |
326 | #endif /* TIOCGLTC */ | |
327 | ||
328 | #ifdef TIOCGETC | |
329 | struct tchars tchars; | |
330 | int lmode; | |
331 | #define EMACS_GET_TTY_3(fd, p) \ | |
332 | (ioctl ((fd), TIOCGETC, &(p)->tchars) != -1 \ | |
333 | && ioctl ((fd), TIOCLGET, &(p)->lmode) != -1) | |
334 | #define EMACS_SET_TTY_3(fd, p, waitp) \ | |
335 | (ioctl ((fd), TIOCSETC, &(p)->tchars) != -1 \ | |
336 | && ioctl ((fd), TIOCLSET, &(p)->lmode) != -1) | |
337 | #else | |
338 | #define EMACS_GET_TTY_3(fd, p) 1 | |
339 | #define EMACS_SET_TTY_3(fd, p, waitp) 1 | |
340 | #endif /* TIOCGLTC */ | |
341 | ||
342 | }; | |
343 | ||
bd307392 | 344 | /* Define these to be a concatenation of all the EMACS_{GET,SET}_TTY_n |
d0d6b7c5 JB |
345 | macros. */ |
346 | #define EMACS_GET_TTY(fd, tc) \ | |
347 | (EMACS_GET_TTY_1 (fd, tc) \ | |
348 | && EMACS_GET_TTY_2 (fd, tc) \ | |
349 | && EMACS_GET_TTY_3 (fd, tc)) | |
350 | ||
351 | #define EMACS_SET_TTY(fd, tc, waitp) \ | |
352 | (EMACS_SET_TTY_1 (fd, tc, waitp) \ | |
353 | && EMACS_SET_TTY_2 (fd, tc, waitp) \ | |
354 | && EMACS_SET_TTY_3 (fd, tc, waitp)) | |
355 | ||
356 | ||
357 | #ifdef HAVE_TERMIOS | |
358 | ||
359 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) | |
360 | ||
361 | #else /* not def HAVE_TERMIOS */ | |
362 | #ifdef HAVE_TERMIO | |
363 | ||
364 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) | |
365 | ||
366 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ | |
367 | #ifdef VMS | |
368 | ||
369 | #define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0) | |
370 | ||
371 | #else | |
372 | ||
373 | #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS) | |
374 | ||
375 | #endif /* not def VMS */ | |
376 | #endif /* not def HAVE_TERMIO */ | |
377 | #endif /* not def HAVE_TERMIOS */ |