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