0
|
1 /* systty.h - System-dependent definitions for terminals.
|
|
2 Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: FSF 19.30. */
|
|
22
|
|
23 #ifndef _XEMACS_SYSTTY_H_
|
|
24 #define _XEMACS_SYSTTY_H_
|
|
25
|
|
26 #ifdef HAVE_TERMIOS
|
|
27 # define HAVE_TCATTR
|
|
28 #endif
|
|
29
|
|
30 /* If we defined these before and we are about to redefine them,
|
|
31 prevent alarming warnings. */
|
|
32 #ifdef BSD_TERMIOS
|
|
33 #undef NL0
|
|
34 #undef NL1
|
|
35 #undef CR0
|
|
36 #undef CR1
|
|
37 #undef CR2
|
|
38 #undef CR3
|
|
39 #undef TAB0
|
|
40 #undef TAB1
|
|
41 #undef TAB2
|
|
42 #undef XTABS
|
|
43 #undef BS0
|
|
44 #undef BS1
|
|
45 #undef FF0
|
|
46 #undef FF1
|
|
47 #undef ECHO
|
|
48 #undef NOFLSH
|
|
49 #undef TOSTOP
|
|
50 #undef FLUSHO
|
|
51 #undef PENDIN
|
|
52 #endif
|
|
53
|
|
54 /* Include the proper files. */
|
|
55
|
|
56 /* XEmacs: TERMIOS is mo' better than TERMIO so we use it if it's
|
|
57 there. Since TERMIO is backward-compatibility stuff if both it
|
|
58 and TERMIOS exist, it's more likely to be broken. */
|
|
59
|
|
60 #if defined (HAVE_TERMIOS)
|
|
61
|
|
62 /***** (1) The TERMIOS way (POSIX style) *****/
|
|
63
|
|
64 # if defined (_AIX) && defined (_I386)
|
|
65 # include <termios.h> /* termios.h needs to be before termio.h */
|
|
66 # include <termio.h>
|
|
67 # else
|
|
68 # if !defined (NO_TERMIO)
|
|
69 # include <termio.h>
|
|
70 # endif
|
|
71 # include <termios.h>
|
|
72 # endif /* _AIX && _I386 */
|
|
73 # ifndef INCLUDED_FCNTL
|
|
74 # define INCLUDED_FCNTL
|
|
75 # include <fcntl.h>
|
|
76 # endif
|
|
77
|
|
78 #elif defined (HAVE_TERMIO)
|
|
79
|
|
80 /***** (2) The TERMIO way (system V style) *****/
|
|
81
|
|
82 # ifdef __DGUX
|
|
83 # include <sys/ioctl.h>
|
|
84 # endif
|
|
85 # ifndef NO_TERMIO
|
|
86 # include <termio.h>
|
|
87 # endif /* not NO_TERMIO */
|
|
88 # ifndef INCLUDED_FCNTL
|
|
89 # define INCLUDED_FCNTL
|
|
90 # include <fcntl.h>
|
|
91 # endif
|
|
92
|
|
93 #elif defined (DOS_NT)
|
|
94
|
|
95 /***** (3) The MSDOS/NT way *****/
|
|
96
|
|
97 /* Nothing doing */
|
|
98
|
209
|
99 #else
|
0
|
100
|
|
101 /***** (4) The BSD way *****/
|
|
102
|
|
103 # ifdef linux /* XEmacs addition -- necessary? */
|
|
104 # include <bsd/sgtty.h>
|
|
105 # else
|
|
106 # include <sgtty.h>
|
|
107 # endif
|
|
108
|
|
109
|
209
|
110 #endif /* HAVE_TERMIOS */
|
0
|
111
|
|
112 /* XEmacs: I don't think we need the following crap. */
|
|
113 #ifdef __GNU_LIBRARY__
|
|
114 #include <termios.h>
|
|
115 #endif
|
|
116
|
|
117 /* Formerly there was a conditional that included sys/filio.h if
|
|
118 USG5_4 was defined, but this is already included in s/usg5-4.h */
|
|
119
|
|
120 /* Generally useful to include this file: */
|
|
121
|
|
122 /* But Sun OS has broken include files and doesn't want it included */
|
209
|
123 #if !defined (DOS_NT) && !defined (WIN32) && !defined (SUNOS4)
|
0
|
124 # include <sys/ioctl.h>
|
|
125 #endif
|
|
126 /* UNIPLUS systems may have FIONREAD. */
|
|
127 #ifdef UNIPLUS
|
|
128 #include <sys.ioctl.h>
|
|
129 #endif
|
|
130
|
|
131
|
|
132 /* ----------------------------------------------------- */
|
|
133 /* miscellaneous includes */
|
|
134 /* ----------------------------------------------------- */
|
|
135
|
|
136 #ifdef AIXHFT
|
|
137 /* Get files for keyboard remapping */
|
|
138 #define HFNKEYS 2
|
|
139 #include <sys/hft.h>
|
|
140 #include <sys/devinfo.h>
|
|
141 #endif
|
|
142
|
|
143 /* XEmacs: We don't support BSD 4.1 any more */
|
|
144
|
|
145 #ifdef NEED_BSDTTY
|
|
146 #include <sys/bsdtty.h>
|
|
147 #endif
|
|
148
|
|
149 /* Include files for PTY's */
|
|
150
|
|
151 #if defined (HPUX) && defined (HAVE_PTYS)
|
|
152 #include <sys/ptyio.h>
|
|
153 #endif
|
|
154
|
|
155 #ifdef AIX
|
|
156 #include <sys/pty.h>
|
|
157 #endif /* AIX */
|
|
158
|
|
159 /* XEmacs: We don't include unistd.h because it's done in lisp.h */
|
|
160
|
|
161 #ifdef SYSV_PTYS
|
|
162 # include <sys/types.h>
|
|
163 # include <sys/tty.h>
|
|
164 # ifdef titan
|
|
165 # include <sys/ttyhw.h>
|
|
166 # include <sys/stream.h>
|
|
167 # endif
|
|
168 # ifndef NO_PTY_H
|
|
169 # include <sys/pty.h>
|
|
170 # endif
|
|
171 #endif
|
|
172
|
|
173 /* XEmacs: removed some random if defined (pfa) crap for FASYNC (SIGIO).
|
|
174 We've cleaned SIGIO up. */
|
|
175
|
|
176
|
|
177 /* ----------------------------------------------------- */
|
|
178 /* inhibiting particular features */
|
|
179 /* ----------------------------------------------------- */
|
|
180
|
|
181
|
|
182 #ifdef APOLLO
|
|
183 #undef TIOCSTART
|
|
184 #endif
|
|
185
|
|
186 #if defined (XENIX) || defined (BROKEN_TIOCGETC)
|
|
187 #undef TIOCGETC /* Avoid confusing some conditionals that test this. */
|
|
188 #endif
|
|
189
|
|
190 /* XEmacs: SIGIO is cleaned up so we remove the crap here that messes
|
|
191 with it (and FIONREAD and FASYNC, which are related). */
|
|
192
|
|
193 #ifdef BROKEN_TIOCGWINSZ /* XEmacs addition */
|
|
194 #undef TIOCGWINSZ
|
|
195 #undef TIOCSWINSZ
|
|
196 #endif
|
|
197
|
|
198 #ifdef BROKEN_O_NONBLOCK /* XEmacs addition */
|
|
199 # undef O_NONBLOCK
|
|
200 #endif /* BROKEN_O_NONBLOCK */
|
|
201
|
|
202 /* On TERMIOS systems, the tcmumbleattr calls take care of these
|
|
203 parameters, and it's a bad idea to use them (on AIX, it makes the
|
|
204 tty hang for a long time). */
|
|
205 #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
|
|
206 #define HAVE_LTCHARS
|
|
207 #endif
|
|
208
|
|
209 #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
|
|
210 #define HAVE_TCHARS
|
|
211 #endif
|
|
212
|
|
213
|
|
214 /* ----------------------------------------------------- */
|
|
215 /* disabling terminal functions */
|
|
216 /* ----------------------------------------------------- */
|
|
217
|
|
218 /* Try to establish the correct character to disable terminal functions
|
|
219 in a system-independent manner. Note that USG (at least) define
|
|
220 _POSIX_VDISABLE as 0! */
|
|
221
|
|
222 #ifdef _POSIX_VDISABLE
|
|
223 #define CDISABLE _POSIX_VDISABLE
|
|
224 #else /* not _POSIX_VDISABLE */
|
|
225 #ifdef CDEL
|
|
226 #undef CDISABLE
|
|
227 #define CDISABLE CDEL
|
|
228 #else /* not CDEL */
|
|
229 #define CDISABLE 255
|
|
230 #endif /* not CDEL */
|
|
231 #endif /* not _POSIX_VDISABLE */
|
|
232
|
|
233
|
|
234 /* ----------------------------------------------------- */
|
|
235 /* Get the number of characters queued for output */
|
|
236 /* ----------------------------------------------------- */
|
|
237
|
|
238 /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
|
|
239 queued for output to the terminal FD in *SIZE, if FD is a tty.
|
|
240 Returns -1 if there was an error (i.e. FD is not a tty), 0
|
|
241 otherwise. */
|
|
242 #ifdef TIOCOUTQ
|
|
243 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TIOCOUTQ, size)
|
|
244 #endif
|
|
245
|
|
246 #ifdef HAVE_TERMIO
|
|
247 #ifdef TCOUTQ
|
|
248 #undef EMACS_OUTQSIZE
|
|
249 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TCOUTQ, size)
|
|
250 #endif
|
|
251 #endif
|
|
252
|
|
253
|
|
254 /* -------------------------------------------------------------------- */
|
|
255 /* Manipulate a terminal's current (foreground) process group */
|
|
256 /* -------------------------------------------------------------------- */
|
|
257
|
|
258 /* EMACS_HAVE_TTY_PGRP is true if we can get and set the tty's current
|
|
259 controlling process group.
|
|
260
|
|
261 EMACS_GET_TTY_PGRP(int FD, int *PGID) sets *PGID the terminal FD's
|
|
262 current process group. Return -1 if there is an error.
|
|
263
|
|
264 EMACS_SET_TTY_PGRP(int FD, int *PGID) sets the terminal FD's
|
|
265 current process group to *PGID. Return -1 if there is an error. */
|
|
266
|
|
267 /* HPUX tty process group stuff doesn't work, says the anonymous voice
|
|
268 from the past. */
|
|
269 /* But HPUX people say it does, so I've removed it. --ben */
|
|
270 # ifdef TIOCGPGRP
|
|
271 # define EMACS_HAVE_TTY_PGRP
|
|
272 # else
|
|
273 # ifdef HAVE_TERMIOS
|
|
274 # define EMACS_HAVE_TTY_PGRP
|
|
275 # endif
|
|
276 # endif
|
|
277
|
|
278 #ifdef EMACS_HAVE_TTY_PGRP
|
|
279
|
|
280 #if defined (HAVE_TERMIOS) && ! defined (BSD_TERMIOS)
|
|
281
|
|
282 /* Resist the urge to insert needless extra parentheses. */
|
|
283 #define EMACS_GET_TTY_PGRP(fd, pgid) (*(pgid) = tcgetpgrp (fd))
|
|
284 #define EMACS_SET_TTY_PGRP(fd, pgid) tcsetpgrp (fd, *(pgid))
|
|
285
|
|
286 #elif defined (TIOCSPGRP)
|
|
287
|
|
288 #define EMACS_GET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCGPGRP, (pgid)))
|
|
289 #define EMACS_SET_TTY_PGRP(fd, pgid) (ioctl ((fd), TIOCSPGRP, (pgid)))
|
|
290
|
|
291 #endif
|
|
292
|
|
293 #endif /* EMACS_HAVE_TTY_PGRP */
|
|
294
|
|
295 #ifndef EMACS_GET_TTY_PGRP
|
|
296
|
|
297 /* Just ignore this for now and hope for the best */
|
|
298 #define EMACS_GET_TTY_PGRP(fd, pgid) 0
|
|
299 #define EMACS_SET_TTY_PGRP(fd, pgif) 0
|
|
300
|
|
301 #endif
|
|
302
|
|
303 /* XEmacs interim backward-compatibility */
|
|
304 #define EMACS_GET_TTY_PROCESS_GROUP EMACS_GET_TTY_PGRP
|
|
305 #define EMACS_SET_TTY_PROCESS_GROUP EMACS_SET_TTY_PGRP
|
|
306
|
|
307 /* EMACS_GETPGRP (arg) returns the process group of the terminal. */
|
|
308
|
163
|
309 #ifdef GETPGRP_VOID
|
|
310 #define EMACS_GETPGRP(x) getpgrp()
|
0
|
311 #else
|
163
|
312 #define EMACS_GETPGRP(x) getpgrp(x)
|
|
313 #endif /* GETPGRP_VOID */
|
0
|
314
|
|
315 /* XEmacs backward-compatibility. Is 0 always a reasonable argument? */
|
|
316 #define EMACS_GET_PROCESS_GROUP() EMACS_GETPGRP (0)
|
|
317
|
203
|
318 /* XEmacs addition? */
|
0
|
319
|
|
320 /* EMACS_SEPARATE_PROCESS_GROUP () creates a separate process group for the
|
|
321 running process. */
|
|
322
|
|
323 /* EMACS_SET_PROCESS_GROUP () sets our process group as specified. */
|
|
324
|
|
325 /* POSIX calls for setpgid(), so we use it if it's available.
|
|
326 Otherwise use setpgrp(), in USG or BSD flavor. Note that
|
|
327 on newer systems, setpgrp() has unwanted effects (e.g.
|
|
328 creating a new session), so we want to avoid its use
|
|
329 if possible.
|
|
330
|
|
331 NOTE: On some older systems, we should consider using setpgrp2()
|
|
332 if it exists. This is sufficiently rare, though, that there
|
|
333 seems no point in autodetecting it. Currently dgux.h is the
|
|
334 only place where this has to be munged. */
|
|
335
|
|
336 #if defined (HAVE_SETPGID)
|
|
337 # define EMACS_SEPARATE_PROCESS_GROUP() setpgid (0, 0)
|
|
338 # define EMACS_SET_PROCESS_GROUP(pg) setpgid (0, pg)
|
|
339 #elif defined (USG)
|
|
340 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp ()
|
|
341 /* old (pre-SVR4) USG's don't provide any way to do this.
|
|
342 No big loss -- it just means that ^Z won't work right
|
|
343 if we're run from sh. */
|
|
344 # define EMACS_SET_PROCESS_GROUP(pg)
|
|
345 #else
|
|
346 /* Under NeXTstep, a process group of 0 is not the same as specifying
|
|
347 your own process ID, so we go ahead and specify it explicitly. */
|
|
348 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp (0, getpid ())
|
|
349 # define EMACS_SET_PROCESS_GROUP(pg) setpgrp (0, pg)
|
|
350 #endif
|
|
351
|
|
352
|
|
353 /* --------------------------------------------------------- */
|
|
354 /* Manipulate a TTY's input/output processing parameters */
|
|
355 /* --------------------------------------------------------- */
|
|
356
|
|
357 /* struct emacs_tty is a structure used to hold the current tty
|
|
358 parameters. If the terminal has several structures describing its
|
|
359 state, for example a struct tchars, a struct sgttyb, a struct
|
|
360 tchars, a struct ltchars, and a struct pagechars, struct
|
|
361 emacs_tty should contain an element for each parameter struct
|
|
362 that Emacs may change.
|
|
363
|
|
364 EMACS_GET_TTY (int FD, struct emacs_tty *P) stores the parameters
|
|
365 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
|
|
366 into an error we couldn't deal with.
|
|
367
|
|
368 EMACS_SET_TTY (int FD, struct emacs_tty *P, int flushp)
|
|
369 sets the parameters of the tty on FD according to the contents of
|
|
370 *P. If flushp is non-zero, we discard queued input to be
|
|
371 written before making the change.
|
|
372 Return 0 if all went well, and -1 if anything failed.
|
|
373
|
|
374 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
|
|
375 expands tabs to spaces upon output; in that case, there is no
|
|
376 advantage to using tabs over spaces. */
|
|
377
|
|
378
|
|
379 /* For each tty parameter structure that Emacs might want to save and restore,
|
|
380 - include an element for it in this structure, and
|
|
381 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
|
|
382 new members. */
|
|
383
|
|
384 struct emacs_tty {
|
|
385
|
|
386 /* There is always one of the following elements, so there is no need
|
|
387 for dummy get and set definitions. */
|
|
388 #ifdef HAVE_TCATTR
|
|
389 struct termios main;
|
175
|
390 #else /* !HAVE_TCATTR */
|
0
|
391 #ifdef HAVE_TERMIO
|
|
392 struct termio main;
|
175
|
393 #else /* !HAVE_TERMIO */
|
0
|
394 #ifdef DOS_NT
|
|
395 int main;
|
|
396 #else /* not DOS_NT */
|
|
397 struct sgttyb main;
|
|
398 #endif /* not DOS_NT */
|
175
|
399 #endif /* !HAVE_TERMIO */
|
|
400 #endif /* !HAVE_TCATTR */
|
0
|
401
|
|
402 /* If we have TERMIOS, we don't need to do this - they're taken care of
|
|
403 by the tc*attr calls. */
|
|
404 #ifndef HAVE_TERMIOS
|
|
405 #ifdef HAVE_LTCHARS
|
|
406 struct ltchars ltchars;
|
175
|
407 #endif /* HAVE_LTCHARS */
|
0
|
408
|
|
409 #ifdef HAVE_TCHARS
|
|
410 struct tchars tchars;
|
|
411 int lmode;
|
175
|
412 #endif /* HAVE_TCHARS */
|
|
413 #endif /* HAVE_TERMIOS */
|
0
|
414 };
|
|
415
|
|
416 /* Define EMACS_GET_TTY and EMACS_SET_TTY,
|
|
417 the macros for reading and setting parts of `struct emacs_tty'.
|
|
418
|
|
419 These got pretty unmanageable (huge macros are hard to debug), and
|
|
420 finally needed some code which couldn't be done as part of an
|
|
421 expression, so we moved them out to their own functions in sysdep.c. */
|
|
422 #define EMACS_GET_TTY(fd, p) emacs_get_tty (fd, p)
|
|
423 #define EMACS_SET_TTY(fd, p, waitp) emacs_set_tty (fd, p, waitp)
|
|
424
|
|
425
|
|
426 /* --------------------------------------------------------- */
|
|
427 /* Define EMACS_TTY_TABS_OK */
|
|
428 /* --------------------------------------------------------- */
|
|
429
|
|
430 #ifdef HAVE_TERMIOS
|
|
431
|
|
432 #ifdef TABDLY
|
|
433 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
|
|
434 #else
|
|
435 #define EMACS_TTY_TABS_OK(p) 1
|
175
|
436 #endif /* TABDLY */
|
0
|
437
|
|
438 #else /* not def HAVE_TERMIOS */
|
|
439 #ifdef HAVE_TERMIO
|
|
440
|
|
441 #define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
|
|
442
|
|
443 #else /* neither HAVE_TERMIO nor HAVE_TERMIOS */
|
|
444 #ifdef DOS_NT
|
|
445 #define EMACS_TTY_TABS_OK(p) 0
|
|
446 #else /* not DOS_NT */
|
|
447 #define EMACS_TTY_TABS_OK(p) (((p)->main.sg_flags & XTABS) != XTABS)
|
|
448 #endif /* not DOS_NT */
|
|
449
|
|
450 #endif /* not def HAVE_TERMIO */
|
|
451 #endif /* not def HAVE_TERMIOS */
|
|
452
|
|
453 #endif /* _XEMACS_SYSTTY_H_ */
|