428
|
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
|
440
|
23 #ifndef INCLUDED_systty_h_
|
|
24 #define INCLUDED_systty_h_
|
428
|
25
|
|
26 #ifdef HAVE_TERMIOS
|
|
27 # define HAVE_TCATTR
|
|
28 #endif
|
|
29
|
|
30
|
|
31 /* Include the proper files. */
|
|
32
|
|
33 #ifdef HAVE_UNISTD_H
|
|
34 #include <unistd.h>
|
|
35 #endif
|
|
36
|
|
37 /* XEmacs: TERMIOS is mo' better than TERMIO so we use it if it's
|
|
38 there. Since TERMIO is backward-compatibility stuff if both it
|
|
39 and TERMIOS exist, it's more likely to be broken. */
|
|
40
|
|
41 #if defined (HAVE_TERMIOS)
|
|
42
|
|
43 /***** (1) The TERMIOS way (POSIX style) *****/
|
|
44
|
|
45 # if defined (_AIX) && defined (_I386)
|
|
46 # include <termios.h> /* termios.h needs to be before termio.h */
|
|
47 # include <termio.h>
|
|
48 # else
|
|
49 # if !defined (NO_TERMIO)
|
|
50 # include <termio.h>
|
|
51 # endif
|
|
52 # include <termios.h>
|
|
53 # endif /* _AIX && _I386 */
|
|
54 # ifndef INCLUDED_FCNTL
|
|
55 # define INCLUDED_FCNTL
|
|
56 # include <fcntl.h>
|
|
57 # endif
|
|
58
|
|
59 #elif defined (HAVE_TERMIO)
|
|
60
|
|
61 /***** (2) The TERMIO way (system V style) *****/
|
|
62
|
|
63 # ifdef __DGUX
|
|
64 # include <sys/ioctl.h>
|
|
65 # endif
|
|
66 # ifndef NO_TERMIO
|
|
67 # include <termio.h>
|
|
68 # endif /* not NO_TERMIO */
|
|
69 # ifndef INCLUDED_FCNTL
|
|
70 # define INCLUDED_FCNTL
|
|
71 # include <fcntl.h>
|
|
72 # endif
|
|
73
|
442
|
74 #elif defined (WIN32_NATIVE)
|
428
|
75
|
442
|
76 /***** (3) The WIN32_NATIVE way *****/
|
428
|
77
|
|
78 /* Nothing doing */
|
|
79
|
|
80 #else
|
|
81
|
|
82 /***** (4) The BSD way *****/
|
|
83
|
|
84 # ifdef linux /* XEmacs addition -- necessary? */
|
|
85 # include <bsd/sgtty.h>
|
|
86 # else
|
|
87 # include <sgtty.h>
|
|
88 # endif
|
|
89
|
|
90
|
|
91 #endif /* HAVE_TERMIOS */
|
|
92
|
|
93 /* XEmacs: I don't think we need the following crap. */
|
|
94 #ifdef __GNU_LIBRARY__
|
|
95 #include <termios.h>
|
|
96 #endif
|
|
97
|
|
98 /* Formerly there was a conditional that included sys/filio.h if
|
|
99 USG5_4 was defined, but this is already included in s/usg5-4.h */
|
|
100
|
|
101 /* Generally useful to include this file: */
|
|
102
|
|
103 /* But Sun OS has broken include files and doesn't want it included */
|
442
|
104 #if !defined (WIN32_NATIVE) && !defined (SUNOS4)
|
428
|
105 # include <sys/ioctl.h>
|
|
106 #endif
|
|
107 /* UNIPLUS systems may have FIONREAD. */
|
|
108 #ifdef UNIPLUS
|
|
109 #include <sys.ioctl.h>
|
|
110 #endif
|
|
111
|
|
112
|
|
113 /* ----------------------------------------------------- */
|
|
114 /* miscellaneous includes */
|
|
115 /* ----------------------------------------------------- */
|
|
116
|
|
117 #ifdef AIXHFT
|
|
118 /* Get files for keyboard remapping */
|
|
119 #define HFNKEYS 2
|
|
120 #include <sys/hft.h>
|
|
121 #include <sys/devinfo.h>
|
|
122 #endif
|
|
123
|
|
124 /* XEmacs: We don't support BSD 4.1 any more */
|
|
125
|
|
126 #ifdef NEED_BSDTTY
|
|
127 #include <sys/bsdtty.h>
|
|
128 #endif
|
|
129
|
|
130 /* Include files for PTY's */
|
|
131
|
|
132 #if defined (HPUX) && defined (HAVE_PTYS)
|
|
133 #include <sys/ptyio.h>
|
|
134 #endif
|
|
135
|
|
136 #ifdef AIX
|
|
137 #include <sys/pty.h>
|
|
138 #endif /* AIX */
|
|
139
|
|
140 #ifdef SYSV_PTYS
|
|
141 # include <sys/types.h>
|
|
142 # include <sys/tty.h>
|
|
143 # ifdef titan
|
|
144 # include <sys/ttyhw.h>
|
|
145 # include <sys/stream.h>
|
|
146 # endif
|
|
147 # ifndef NO_PTY_H
|
|
148 # include <sys/pty.h>
|
|
149 # endif
|
|
150 #endif
|
|
151
|
|
152 /* XEmacs: removed some random if defined (pfa) crap for FASYNC (SIGIO).
|
|
153 We've cleaned SIGIO up. */
|
|
154
|
|
155
|
|
156 /* ----------------------------------------------------- */
|
|
157 /* inhibiting particular features */
|
|
158 /* ----------------------------------------------------- */
|
|
159
|
|
160
|
|
161 #if defined (XENIX) || defined (BROKEN_TIOCGETC)
|
|
162 #undef TIOCGETC /* Avoid confusing some conditionals that test this. */
|
|
163 #endif
|
|
164
|
|
165 /* XEmacs: SIGIO is cleaned up so we remove the crap here that messes
|
|
166 with it (and FIONREAD and FASYNC, which are related). */
|
|
167
|
|
168 #ifdef BROKEN_TIOCGWINSZ /* XEmacs addition */
|
|
169 #undef TIOCGWINSZ
|
|
170 #undef TIOCSWINSZ
|
|
171 #endif
|
|
172
|
|
173 /* On TERMIOS systems, the tcmumbleattr calls take care of these
|
|
174 parameters, and it's a bad idea to use them (on AIX, it makes the
|
|
175 tty hang for a long time). */
|
|
176 #if defined (TIOCGLTC) && !defined (HAVE_TERMIOS)
|
|
177 #define HAVE_LTCHARS
|
|
178 #endif
|
|
179
|
|
180 #if defined (TIOCGETC) && !defined (HAVE_TERMIOS)
|
|
181 #define HAVE_TCHARS
|
|
182 #endif
|
|
183
|
|
184
|
|
185 /* ----------------------------------------------------- */
|
|
186 /* disabling terminal functions */
|
|
187 /* ----------------------------------------------------- */
|
|
188
|
|
189 /* Try to establish the correct character to disable terminal functions
|
|
190 in a system-independent manner.
|
|
191 We use the POSIX standard way to do this, and emulate on other systems. */
|
|
192
|
|
193 #ifndef _POSIX_VDISABLE
|
|
194 # if defined CDEL
|
|
195 # define _POSIX_VDISABLE CDEL
|
|
196 # else
|
|
197 # define _POSIX_VDISABLE 255
|
|
198 # endif
|
|
199 #endif /* ! _POSIX_VDISABLE */
|
|
200
|
|
201
|
|
202 /* ----------------------------------------------------- */
|
|
203 /* Get the number of characters queued for output */
|
|
204 /* ----------------------------------------------------- */
|
|
205
|
|
206 /* EMACS_OUTQSIZE(FD, int *SIZE) stores the number of characters
|
|
207 queued for output to the terminal FD in *SIZE, if FD is a tty.
|
|
208 Returns -1 if there was an error (i.e. FD is not a tty), 0
|
|
209 otherwise. */
|
|
210 #ifdef TIOCOUTQ
|
|
211 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TIOCOUTQ, size)
|
|
212 #endif
|
|
213
|
|
214 #ifdef HAVE_TERMIO
|
|
215 #ifdef TCOUTQ
|
|
216 #undef EMACS_OUTQSIZE
|
|
217 #define EMACS_OUTQSIZE(fd, size) ioctl (fd, TCOUTQ, size)
|
|
218 #endif
|
|
219 #endif
|
|
220
|
|
221
|
|
222 /* -------------------------------------------------------------------- */
|
|
223 /* Manipulate a terminal's current (foreground) process group */
|
|
224 /* -------------------------------------------------------------------- */
|
|
225
|
442
|
226 /* EMACS_GET_TTY_PGRP(int FD, pid_t *PGID) sets *PGID to the terminal
|
|
227 FD's current foreground process group. Return -1 if there is an error.
|
|
228
|
|
229 EMACS_SET_TTY_PGRP(int FD, pid_t *PGID) sets the terminal FD's current
|
|
230 foreground process group to *PGID. Return -1 if there is an error.
|
428
|
231
|
442
|
232 We prefer using the ioctl (BSD) interface instead of its Posix
|
|
233 replacement tgetpgrp/tcsetpgrp since that is documented as being
|
|
234 restricted to processes sharing the same controlling tty. */
|
428
|
235
|
442
|
236 #if defined (TIOCGPGRP)
|
428
|
237
|
442
|
238 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCGPGRP, pgid)
|
|
239 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) ioctl (fd, TIOCSPGRP, pgid)
|
|
240
|
|
241 #elif defined (HAVE_TCGETPGRP)
|
428
|
242
|
442
|
243 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) (*(pgid) = tcgetpgrp (fd))
|
|
244 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgid) tcsetpgrp (fd, *(pgid))
|
428
|
245
|
442
|
246 #else
|
428
|
247
|
442
|
248 /* Just ignore this for now and hope for the best */
|
|
249 #define EMACS_GET_TTY_PROCESS_GROUP(fd, pgid) 0
|
|
250 #define EMACS_SET_TTY_PROCESS_GROUP(fd, pgif) 0
|
428
|
251
|
|
252 #endif
|
|
253
|
|
254 /* EMACS_GETPGRP (arg) returns the process group of the terminal. */
|
|
255
|
|
256 #ifdef GETPGRP_VOID
|
|
257 #define EMACS_GETPGRP(x) getpgrp()
|
|
258 #else
|
|
259 #define EMACS_GETPGRP(x) getpgrp(x)
|
|
260 #endif /* GETPGRP_VOID */
|
|
261
|
|
262 /* XEmacs backward-compatibility. Is 0 always a reasonable argument? */
|
|
263 #define EMACS_GET_PROCESS_GROUP() EMACS_GETPGRP (0)
|
|
264
|
|
265 /* XEmacs addition? */
|
|
266
|
|
267 /* EMACS_SEPARATE_PROCESS_GROUP () creates a separate process group for the
|
|
268 running process. */
|
|
269
|
|
270 /* EMACS_SET_PROCESS_GROUP () sets our process group as specified. */
|
|
271
|
|
272 /* POSIX calls for setpgid(), so we use it if it's available.
|
|
273 Otherwise use setpgrp(), in USG or BSD flavor. Note that
|
|
274 on newer systems, setpgrp() has unwanted effects (e.g.
|
|
275 creating a new session), so we want to avoid its use
|
|
276 if possible.
|
|
277
|
|
278 NOTE: On some older systems, we should consider using setpgrp2()
|
|
279 if it exists. This is sufficiently rare, though, that there
|
|
280 seems no point in autodetecting it. Currently dgux.h is the
|
|
281 only place where this has to be munged. */
|
|
282
|
|
283 #if defined (HAVE_SETPGID)
|
|
284 # define EMACS_SEPARATE_PROCESS_GROUP() setpgid (0, 0)
|
|
285 # define EMACS_SET_PROCESS_GROUP(pg) setpgid (0, pg)
|
|
286 #elif defined (USG)
|
|
287 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp ()
|
|
288 /* old (pre-SVR4) USG's don't provide any way to do this.
|
|
289 No big loss -- it just means that ^Z won't work right
|
|
290 if we're run from sh. */
|
|
291 # define EMACS_SET_PROCESS_GROUP(pg)
|
442
|
292 #elif defined(MINGW)
|
432
|
293 # define EMACS_SEPARATE_PROCESS_GROUP()
|
428
|
294 #else
|
|
295 /* Under NeXTstep, a process group of 0 is not the same as specifying
|
|
296 your own process ID, so we go ahead and specify it explicitly. */
|
|
297 # define EMACS_SEPARATE_PROCESS_GROUP() setpgrp (0, getpid ())
|
|
298 # define EMACS_SET_PROCESS_GROUP(pg) setpgrp (0, pg)
|
|
299 #endif
|
|
300
|
|
301
|
|
302 /* --------------------------------------------------------- */
|
|
303 /* Manipulate a TTY's input/output processing parameters */
|
|
304 /* --------------------------------------------------------- */
|
|
305
|
|
306 /* struct emacs_tty is a structure used to hold the current tty
|
|
307 parameters. If the terminal has several structures describing its
|
|
308 state, for example a struct tchars, a struct sgttyb, a struct
|
|
309 tchars, a struct ltchars, and a struct pagechars, struct
|
|
310 emacs_tty should contain an element for each parameter struct
|
|
311 that Emacs may change.
|
|
312
|
430
|
313 emacs_get_tty (int FD, struct emacs_tty *P) stores the parameters
|
428
|
314 of the tty on FD in *P. Return zero if all's well, or -1 if we ran
|
|
315 into an error we couldn't deal with.
|
|
316
|
430
|
317 emacs_set_tty (int FD, struct emacs_tty *P, int flushp)
|
428
|
318 sets the parameters of the tty on FD according to the contents of
|
|
319 *P. If flushp is non-zero, we discard queued input to be
|
|
320 written before making the change.
|
|
321 Return 0 if all went well, and -1 if anything failed.
|
|
322
|
|
323 EMACS_TTY_TABS_OK (struct emacs_tty *P) is false iff the kernel
|
|
324 expands tabs to spaces upon output; in that case, there is no
|
|
325 advantage to using tabs over spaces. */
|
|
326
|
|
327
|
|
328 /* For each tty parameter structure that Emacs might want to save and restore,
|
|
329 - include an element for it in this structure, and
|
|
330 - extend the emacs_{get,set}_tty functions in sysdep.c to deal with the
|
|
331 new members. */
|
|
332
|
|
333 struct emacs_tty {
|
|
334
|
|
335 /* There is always one of the following elements, so there is no need
|
|
336 for dummy get and set definitions. */
|
|
337 #ifdef HAVE_TCATTR
|
|
338 struct termios main;
|
|
339 #else /* !HAVE_TCATTR */
|
|
340 #ifdef HAVE_TERMIO
|
|
341 struct termio main;
|
|
342 #else /* !HAVE_TERMIO */
|
442
|
343 #ifdef WIN32_NATIVE
|
428
|
344 int main;
|
442
|
345 #else /* not WIN32_NATIVE */
|
428
|
346 struct sgttyb main;
|
442
|
347 #endif /* not WIN32_NATIVE */
|
428
|
348 #endif /* !HAVE_TERMIO */
|
|
349 #endif /* !HAVE_TCATTR */
|
|
350
|
|
351 /* If we have TERMIOS, we don't need to do this - they're taken care of
|
|
352 by the tc*attr calls. */
|
|
353 #ifndef HAVE_TERMIOS
|
|
354 #ifdef HAVE_LTCHARS
|
|
355 struct ltchars ltchars;
|
|
356 #endif /* HAVE_LTCHARS */
|
|
357
|
|
358 #ifdef HAVE_TCHARS
|
|
359 struct tchars tchars;
|
|
360 int lmode;
|
|
361 #endif /* HAVE_TCHARS */
|
|
362 #endif /* HAVE_TERMIOS */
|
|
363 };
|
|
364
|
430
|
365 int emacs_get_tty (int fd, struct emacs_tty *settings);
|
|
366 int emacs_set_tty (int fd, struct emacs_tty *settings, int flushp);
|
428
|
367
|
|
368
|
|
369 /* --------------------------------------------------------- */
|
|
370 /* Define EMACS_TTY_TABS_OK */
|
|
371 /* --------------------------------------------------------- */
|
|
372
|
513
|
373 #if defined (TABDLY) && defined (TAB3)
|
|
374 # define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & TABDLY) != TAB3)
|
|
375 #elif defined (OXTABS)
|
|
376 # define EMACS_TTY_TABS_OK(p) (((p)->main.c_oflag & OXTABS) != OXTABS)
|
428
|
377 #else
|
513
|
378 # define EMACS_TTY_TABS_OK(p) 1
|
|
379 #endif
|
428
|
380
|
440
|
381 #endif /* INCLUDED_systty_h_ */
|