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