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