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