Commit | Line | Data |
---|---|---|
d0d6b7c5 JB |
1 | /* systerm.h - System-dependent definitions for terminals. |
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> | |
29 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ | |
30 | #ifndef VMS | |
31 | #include <sgtty.h> | |
32 | #endif /* not VMS */ | |
33 | #endif /* not HAVE_TERMIOS */ | |
34 | #endif /* not HAVE_TERMIO */ | |
35 | ||
4746118a JB |
36 | #ifdef AIX |
37 | /* Get files for keyboard remapping */ | |
38 | #define HFNKEYS 2 | |
39 | #include <sys/hft.h> | |
40 | #include <sys/devinfo.h> | |
41 | #endif | |
42 | ||
43 | /* Get rid of LLITOUT in 4.1, since it is said to stimulate kernel bugs. */ | |
44 | #ifdef BSD4_1 | |
45 | #undef LLITOUT | |
46 | #define LLITOUT 0 | |
47 | #endif /* 4.1 */ | |
48 | ||
49 | #ifdef NEED_BSDTTY | |
50 | #include <sys/bsdtty.h> | |
51 | #endif | |
52 | ||
53 | #if defined (HPUX) && defined (HAVE_PTYS) | |
54 | #include <sys/ptyio.h> | |
55 | #endif | |
56 | ||
57 | #ifdef AIX | |
58 | #include <sys/pty.h> | |
59 | #include <unistd.h> | |
60 | #endif /* AIX */ | |
61 | ||
62 | #ifdef SYSV_PTYS | |
63 | #include <sys/tty.h> | |
64 | #include <sys/pty.h> | |
65 | #endif | |
66 | ||
67 | /* saka@pfu.fujitsu.co.JP writes: | |
68 | FASYNC defined in this file. But, FASYNC don't working. | |
69 | so no problem, because unrequest_sigio only need. */ | |
70 | #if defined (pfa) | |
71 | #include <sys/file.h> | |
72 | #endif | |
73 | ||
d0d6b7c5 JB |
74 | \f |
75 | /* Special cases - inhibiting the use of certain features. */ | |
76 | ||
77 | #ifdef APOLLO | |
78 | #undef TIOCSTART | |
79 | #endif | |
80 | ||
81 | #ifdef BROKEN_TIOCGETC | |
82 | #undef TIOCGETC /* Avoid confusing some conditionals that test this. */ | |
83 | #endif | |
84 | ||
85 | /* UNIPLUS systems may have FIONREAD. */ | |
86 | #ifdef UNIPLUS | |
87 | #include <sys.ioctl.h> | |
88 | #endif | |
89 | ||
90 | /* Allow m- file to inhibit use of FIONREAD. */ | |
91 | #ifdef BROKEN_FIONREAD | |
92 | #undef FIONREAD | |
93 | #undef ASYNC | |
94 | #endif | |
95 | ||
96 | /* Interupt input is not used if there is no FIONREAD. */ | |
97 | #ifndef FIONREAD | |
98 | #undef SIGIO | |
99 | #endif | |
100 | ||
101 | \f | |
102 | /* Get the number of characters queued for output. */ | |
103 | ||
104 | /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters | |
105 | queued for output to the terminal FD in *SIZE, if FD is a tty. | |
106 | Returns -1 if there was an error (i.e. FD is not a tty), 0 | |
107 | otherwise. */ | |
108 | #ifdef TIOCOUTQ | |
109 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TIOCOUTQ, (size))) | |
110 | #endif | |
111 | ||
112 | #ifdef HAVE_TERMIO | |
113 | #ifdef TCOUTQ | |
114 | #undef EMACS_OUTQSIZE | |
115 | #define EMACS_OUTQSIZE(fd, size) (ioctl ((fd), TCOUTQ, (size))) | |
116 | #endif | |
117 | #endif | |
118 | ||
119 | \f | |
120 | /* Manipulate a terminal's current process group. */ | |
121 | ||
122 | /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current | |
123 | controlling process group. | |
124 | ||
125 | EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's | |
126 | current process group. Return -1 if there is an error. | |
127 | ||
128 | EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's | |
129 | current process group to *PGID. Return -1 if there is an error. */ | |
130 | ||
131 | #ifdef TIOCGPGRP | |
132 | #define EMACS_HAVE_TTY_PGRP | |
133 | #else | |
134 | #ifdef HAVE_TERMIOS | |
135 | #define EMACS_HAVE_TTY_PGRP | |
136 | #endif | |
137 | #endif | |
138 | ||
139 | #ifdef EMACS_HAVE_TTY_PGRP | |
140 | ||
141 | #ifdef HAVE_TERMIOS | |
142 | ||
143 | #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp ((fd))) | |
144 | #define EMACS_SET_TTY_PGRP(fd, pgid) (*(pgid) = tcsetpgrp ((fd))) | |
145 | ||
146 | #else | |
147 | #ifdef TIOCSPGRP | |
148 | ||
149 | #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid))) | |
150 | #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid))) | |
151 | ||
152 | #endif | |
153 | #endif | |
154 | ||
155 | #else | |
156 | ||
157 | /* Just ignore this for now and hope for the best */ | |
158 | #define EMACS_GET_TTY_PGRP(fd, pgid) 0 | |
159 | ||
160 | #endif | |
161 | ||
162 | \f | |
163 | /* Manipulate a TTY's input/output processing parameters. */ | |
164 | ||
165 | /* struct emacs_tty is a structure used to hold the current tty | |
166 | parameters. If the terminal has several structures describing its | |
167 | state, for example a struct tchars, a struct sgttyb, a struct | |
168 | tchars, a struct ltchars, and a struct pagechars, struct | |
169 | emacs_tty should contain an element for each parameter struct | |
170 | that Emacs may change. | |
171 | ||
172 | EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the | |
173 | parameters of the tty on FD in *P. | |
174 | ||
175 | EMACS_SET_TTY (int FD, struct emacs_tty *P, int waitp) | |
176 | sets the parameters of the tty on FD according to the contents of | |
177 | *P. If waitp is non-zero, we wait for all queued output to be | |
178 | written before making the change; otherwise, we forget any queued | |
179 | input and make the change immediately. | |
180 | ||
181 | EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel | |
182 | expands tabs to spaces upon output; in that case, there is no | |
183 | advantage to using tabs over spaces. */ | |
184 | ||
185 | ||
186 | ||
187 | /* For each tty parameter structure that Emacs might want to save and restore, | |
188 | - include an element for it in this structure, | |
189 | - define a pair of numbered macros to get and set it and return | |
190 | true iff the call succeeded, | |
191 | - give alternative definitions for when the component is not implemented | |
192 | which always succeed, and | |
193 | - extend the definition of EMACS_{GET,SET}_TTY_CHARS to include the | |
194 | new macros. */ | |
195 | ||
196 | struct emacs_tty { | |
197 | ||
198 | /* There is always one of the following elements, so there is no need | |
199 | for dummy get and set definitions. */ | |
200 | #ifdef HAVE_TERMIOS | |
201 | struct termios main; | |
202 | #else | |
203 | #ifdef HAVE_TERMIO | |
204 | struct termio main; | |
205 | #else | |
206 | #ifdef VMS | |
207 | struct sensemode main; | |
208 | #else | |
209 | struct sgttyb main; | |
210 | #endif | |
211 | #endif | |
212 | #endif | |
213 | ||
214 | #ifdef HAVE_TERMIOS | |
215 | #define HAVE_TCATTR | |
216 | #endif | |
217 | ||
218 | #ifdef HAVE_TCATTR | |
219 | ||
220 | #define EMACS_GET_TTY_1(fd, p) (tcgetattr ((fd), &(p)->main) != -1) | |
221 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
222 | (tcsetattr ((fd), (waitp) ? TCSAFLUSH : TCSADRAIN, &(p)->main) != -1) | |
223 | ||
4746118a JB |
224 | #else |
225 | #ifdef HAVE_TERMIO | |
226 | ||
227 | #define EMACS_GET_TTY_1(fd, p) (ioctl ((fd), TCGETA, &(p)->main) != -1) | |
228 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
229 | (ioctl ((fd), (waitp) ? TCSETAW : TCSETAF, &(p)->main) != -1) | |
230 | ||
d0d6b7c5 JB |
231 | #else |
232 | #ifdef VMS | |
233 | ||
234 | /* These definitions will really only work in sysdep.c, because of their | |
235 | use of input_iosb. I don't know enough about VMS QIO to fix this. */ | |
236 | #define EMACS_GET_TTY_1(fd, p) \ | |
237 | SYS$QIOW (0, (fd), IO$_SENSEMODE, (p), 0, 0, \ | |
238 | &(p)->main.class, 12, 0, 0, 0, 0); | |
239 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
240 | SYS$QIOW (0, (fd), IO$_SETMODE, &input_iosb, 0, 0, \ | |
241 | &(p)->main.class, 12, 0, 0, 0, 0); | |
242 | ||
243 | #else | |
244 | ||
245 | #define EMACS_GET_TTY_1(fd, p) (ioctl ((fd), TIOCGETP, &(p)->main) != -1) | |
246 | #define EMACS_SET_TTY_1(fd, p, waitp) \ | |
247 | (ioctl ((fd), (waitp) ? TIOCSETP : TIOCSETN, &(p)->main) != -1) | |
248 | ||
249 | #endif | |
250 | #endif | |
4746118a | 251 | #endif |
d0d6b7c5 JB |
252 | |
253 | #ifdef TIOCGLTC | |
254 | struct ltchars ltchars; | |
255 | #define EMACS_GET_TTY_2(fd, p) \ | |
256 | (ioctl ((fd), TIOCGLTC, &(p)->ltchars) != -1) | |
257 | #define EMACS_SET_TTY_2(fd, p, waitp) \ | |
258 | (ioctl ((fd), TIOCSLTC, &(p)->ltchars) != -1) | |
259 | #else | |
260 | #define EMACS_GET_TTY_2(fd, p) 1 | |
261 | #define EMACS_SET_TTY_2(fd, p, waitp) 1 | |
262 | #endif /* TIOCGLTC */ | |
263 | ||
264 | #ifdef TIOCGETC | |
265 | struct tchars tchars; | |
266 | int lmode; | |
267 | #define EMACS_GET_TTY_3(fd, p) \ | |
268 | (ioctl ((fd), TIOCGETC, &(p)->tchars) != -1 \ | |
269 | && ioctl ((fd), TIOCLGET, &(p)->lmode) != -1) | |
270 | #define EMACS_SET_TTY_3(fd, p, waitp) \ | |
271 | (ioctl ((fd), TIOCSETC, &(p)->tchars) != -1 \ | |
272 | && ioctl ((fd), TIOCLSET, &(p)->lmode) != -1) | |
273 | #else | |
274 | #define EMACS_GET_TTY_3(fd, p) 1 | |
275 | #define EMACS_SET_TTY_3(fd, p, waitp) 1 | |
276 | #endif /* TIOCGLTC */ | |
277 | ||
278 | }; | |
279 | ||
280 | /* Define these to be a concatenation of all the EMACS_{GET,SET}_TTY | |
281 | macros. */ | |
282 | #define EMACS_GET_TTY(fd, tc) \ | |
283 | (EMACS_GET_TTY_1 (fd, tc) \ | |
284 | && EMACS_GET_TTY_2 (fd, tc) \ | |
285 | && EMACS_GET_TTY_3 (fd, tc)) | |
286 | ||
287 | #define EMACS_SET_TTY(fd, tc, waitp) \ | |
288 | (EMACS_SET_TTY_1 (fd, tc, waitp) \ | |
289 | && EMACS_SET_TTY_2 (fd, tc, waitp) \ | |
290 | && EMACS_SET_TTY_3 (fd, tc, waitp)) | |
291 | ||
292 | ||
293 | #ifdef HAVE_TERMIOS | |
294 | ||
295 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) | |
296 | ||
297 | #else /* not def HAVE_TERMIOS */ | |
298 | #ifdef HAVE_TERMIO | |
299 | ||
300 | #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3) | |
301 | ||
302 | #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */ | |
303 | #ifdef VMS | |
304 | ||
305 | #define EMACS_TTY_TABS_OK(p) (((p)->main.tt_char & TT$M_MECHTAB) != 0) | |
306 | ||
307 | #else | |
308 | ||
309 | #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS) | |
310 | ||
311 | #endif /* not def VMS */ | |
312 | #endif /* not def HAVE_TERMIO */ | |
313 | #endif /* not def HAVE_TERMIOS */ |