cleanup exit status handling
[dragonfly.git] / lib / libedit / tty.h
1 /*-
2  * Copyright (c) 1992, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Christos Zoulas of Cornell University.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by the University of
19  *      California, Berkeley and its contributors.
20  * 4. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  *
36  *      @(#)tty.h       8.1 (Berkeley) 6/4/93
37  * $DragonFly: src/lib/libedit/tty.h,v 1.3 2003/11/12 20:21:29 eirikn Exp $
38  */
39
40 /*
41  * el.tty.h: Local terminal header
42  */
43 #ifndef _h_el_tty
44 #define _h_el_tty
45
46 #include "histedit.h"
47 #include <termios.h>
48
49 /* Define our own since everyone gets it wrong! */
50 #define CONTROL(A)      ((A) & 037)
51
52 /*
53  * Aix compatible names
54  */
55 # if defined(VWERSE) && !defined(VWERASE)
56 #  define VWERASE VWERSE
57 # endif /* VWERSE && !VWERASE */
58
59 # if defined(VDISCRD) && !defined(VDISCARD)
60 #  define VDISCARD VDISCRD
61 # endif /* VDISCRD && !VDISCARD */
62
63 # if defined(VFLUSHO) && !defined(VDISCARD)
64 #  define VDISCARD VFLUSHO
65 # endif  /* VFLUSHO && VDISCARD */
66
67 # if defined(VSTRT) && !defined(VSTART)
68 #  define VSTART VSTRT
69 # endif /* VSTRT && ! VSTART */
70
71 # if defined(VSTAT) && !defined(VSTATUS)
72 #  define VSTATUS VSTAT
73 # endif /* VSTAT && ! VSTATUS */
74
75 # ifndef ONLRET
76 #  define ONLRET 0
77 # endif /* ONLRET */
78
79 # ifndef TAB3
80 #  ifdef OXTABS
81 #   define TAB3 OXTABS
82 #  else
83 #   define TAB3 0
84 #  endif /* OXTABS */
85 # endif /* !TAB3 */
86
87 # if defined(OXTABS) && !defined(XTABS)
88 #  define XTABS OXTABS
89 # endif /* OXTABS && !XTABS */
90
91 # ifndef ONLCR
92 #  define ONLCR 0
93 # endif /* ONLCR */
94
95 # ifndef IEXTEN
96 #  define IEXTEN 0
97 # endif /* IEXTEN */
98
99 # ifndef ECHOCTL
100 #  define ECHOCTL 0
101 # endif /* ECHOCTL */
102
103 # ifndef PARENB
104 #  define PARENB 0
105 # endif /* PARENB */
106
107 # ifndef EXTPROC
108 #  define EXTPROC 0
109 # endif /* EXTPROC */
110
111 # ifndef FLUSHO
112 #  define FLUSHO  0
113 # endif /* FLUSHO */
114
115
116 # if defined(VDISABLE) && !defined(_POSIX_VDISABLE)
117 #  define _POSIX_VDISABLE VDISABLE
118 # endif /* VDISABLE && ! _POSIX_VDISABLE */
119
120 /*
121  * Work around ISC's definition of IEXTEN which is
122  * XCASE!
123  */
124 # ifdef ISC
125 #  if defined(IEXTEN) && defined(XCASE)
126 #   if IEXTEN == XCASE
127 #    undef IEXTEN
128 #    define IEXTEN 0
129 #   endif /* IEXTEN == XCASE */
130 #  endif /* IEXTEN && XCASE */
131 #  if defined(IEXTEN) && !defined(XCASE)
132 #   define XCASE IEXTEN
133 #   undef IEXTEN
134 #   define IEXTEN 0
135 #  endif /* IEXTEN && !XCASE */
136 # endif /* ISC */
137
138 /*
139  * Work around convex weirdness where turning off IEXTEN makes us
140  * lose all postprocessing!
141  */
142 #if defined(convex) || defined(__convex__)
143 # if defined(IEXTEN) && IEXTEN != 0
144 #  undef IEXTEN
145 #  define IEXTEN 0
146 # endif /* IEXTEN != 0 */
147 #endif /* convex || __convex__ */
148
149 /*
150  * So that we don't lose job control.
151  */
152 #ifdef __SVR4
153 # undef CSWTCH
154 #endif
155
156 #ifndef _POSIX_VDISABLE
157 # define _POSIX_VDISABLE ((unsigned char) -1)
158 #endif /* _POSIX_VDISABLE */
159
160 #if !defined(CREPRINT) && defined(CRPRNT)
161 # define CREPRINT CRPRNT
162 #endif /* !CREPRINT && CRPRNT */
163 #if !defined(CDISCARD) && defined(CFLUSH)
164 # define CDISCARD CFLUSH
165 #endif /* !CDISCARD && CFLUSH */
166
167 #ifndef CINTR
168 # define CINTR          CONTROL('c')
169 #endif /* CINTR */
170 #ifndef CQUIT
171 # define CQUIT          034     /* ^\ */
172 #endif /* CQUIT */
173 #ifndef CERASE
174 # define CERASE         0177    /* ^? */
175 #endif /* CERASE */
176 #ifndef CKILL
177 # define CKILL          CONTROL('u')
178 #endif /* CKILL */
179 #ifndef CEOF
180 # define CEOF           CONTROL('d')
181 #endif /* CEOF */
182 #ifndef CEOL
183 # define CEOL           _POSIX_VDISABLE
184 #endif /* CEOL */
185 #ifndef CEOL2
186 # define CEOL2          _POSIX_VDISABLE
187 #endif /* CEOL2 */
188 #ifndef CSWTCH
189 # define CSWTCH         _POSIX_VDISABLE
190 #endif /* CSWTCH */
191 #ifndef CDSWTCH
192 # define CDSWTCH        _POSIX_VDISABLE
193 #endif /* CDSWTCH */
194 #ifndef CERASE2
195 # define CERASE2        _POSIX_VDISABLE
196 #endif /* CERASE2 */
197 #ifndef CSTART
198 # define CSTART         CONTROL('q')
199 #endif /* CSTART */
200 #ifndef CSTOP
201 # define CSTOP          CONTROL('s')
202 #endif /* CSTOP */
203 #ifndef CSUSP
204 # define CSUSP          CONTROL('z')
205 #endif /* CSUSP */
206 #ifndef CDSUSP
207 # define CDSUSP         CONTROL('y')
208 #endif /* CDSUSP */
209
210 #ifdef hpux
211
212 # ifndef CREPRINT
213 #  define CREPRINT      _POSIX_VDISABLE
214 # endif /* CREPRINT */
215 # ifndef CDISCARD
216 #  define CDISCARD      _POSIX_VDISABLE
217 # endif /* CDISCARD */
218 # ifndef CLNEXT
219 #  define CLNEXT        _POSIX_VDISABLE
220 # endif /* CLNEXT */
221 # ifndef CWERASE
222 #  define CWERASE       _POSIX_VDISABLE
223 # endif /* CWERASE */
224
225 #else /* !hpux */
226
227 # ifndef CREPRINT
228 #  define CREPRINT      CONTROL('r')
229 # endif /* CREPRINT */
230 # ifndef CDISCARD
231 #  define CDISCARD      CONTROL('o')
232 # endif /* CDISCARD */
233 # ifndef CLNEXT
234 #  define CLNEXT        CONTROL('v')
235 # endif /* CLNEXT */
236 # ifndef CWERASE
237 #  define CWERASE       CONTROL('w')
238 # endif /* CWERASE */
239
240 #endif /* hpux */
241
242 #ifndef CSTATUS
243 # define CSTATUS        CONTROL('t')
244 #endif /* CSTATUS */
245 #ifndef CPAGE
246 # define CPAGE          ' '
247 #endif /* CPAGE */
248 #ifndef CPGOFF
249 # define CPGOFF         CONTROL('m')
250 #endif /* CPGOFF */
251 #ifndef CKILL2
252 # define CKILL2         _POSIX_VDISABLE
253 #endif /* CKILL2 */
254 #ifndef CBRK
255 # ifndef masscomp
256 #  define CBRK          0377
257 # else
258 #  define CBRK          '\0'
259 # endif /* masscomp */
260 #endif /* CBRK */
261 #ifndef CMIN
262 # define CMIN           CEOF
263 #endif /* CMIN */
264 #ifndef CTIME
265 # define CTIME          CEOL
266 #endif /* CTIME */
267
268 /*
269  * Fix for sun inconsistency. On termio VSUSP and the rest of the
270  * ttychars > NCC are defined. So we undefine them.
271  */
272 #if defined(TERMIO) || defined(POSIX)
273 # if defined(POSIX) && defined(NCCS)
274 #  define NUMCC         NCCS
275 # else
276 #  ifdef NCC
277 #   define NUMCC        NCC
278 #  endif /* NCC */
279 # endif /* POSIX && NCCS */
280 # ifdef NUMCC
281 #  ifdef VINTR
282 #   if NUMCC <= VINTR
283 #    undef VINTR
284 #   endif /* NUMCC <= VINTR */
285 #  endif /* VINTR */
286 #  ifdef VQUIT
287 #   if NUMCC <= VQUIT
288 #    undef VQUIT
289 #   endif /* NUMCC <= VQUIT */
290 #  endif /* VQUIT */
291 #  ifdef VERASE
292 #   if NUMCC <= VERASE
293 #    undef VERASE
294 #   endif /* NUMCC <= VERASE */
295 #  endif /* VERASE */
296 #  ifdef VKILL
297 #   if NUMCC <= VKILL
298 #    undef VKILL
299 #   endif /* NUMCC <= VKILL */
300 #  endif /* VKILL */
301 #  ifdef VEOF
302 #   if NUMCC <= VEOF
303 #    undef VEOF
304 #   endif /* NUMCC <= VEOF */
305 #  endif /* VEOF */
306 #  ifdef VEOL
307 #   if NUMCC <= VEOL
308 #    undef VEOL
309 #   endif /* NUMCC <= VEOL */
310 #  endif /* VEOL */
311 #  ifdef VEOL2
312 #   if NUMCC <= VEOL2
313 #    undef VEOL2
314 #   endif /* NUMCC <= VEOL2 */
315 #  endif /* VEOL2 */
316 #  ifdef VSWTCH
317 #   if NUMCC <= VSWTCH
318 #    undef VSWTCH
319 #   endif /* NUMCC <= VSWTCH */
320 #  endif /* VSWTCH */
321 #  ifdef VDSWTCH
322 #   if NUMCC <= VDSWTCH
323 #    undef VDSWTCH
324 #   endif /* NUMCC <= VDSWTCH */
325 #  endif /* VDSWTCH */
326 #  ifdef VERASE2
327 #   if NUMCC <= VERASE2
328 #    undef VERASE2
329 #   endif /* NUMCC <= VERASE2 */
330 #  endif /* VERASE2 */
331 #  ifdef VSTART
332 #   if NUMCC <= VSTART
333 #    undef VSTART
334 #   endif /* NUMCC <= VSTART */
335 #  endif /* VSTART */
336 #  ifdef VSTOP
337 #   if NUMCC <= VSTOP
338 #    undef VSTOP
339 #   endif /* NUMCC <= VSTOP */
340 #  endif /* VSTOP */
341 #  ifdef VWERASE
342 #   if NUMCC <= VWERASE
343 #    undef VWERASE
344 #   endif /* NUMCC <= VWERASE */
345 #  endif /* VWERASE */
346 #  ifdef VSUSP
347 #   if NUMCC <= VSUSP
348 #    undef VSUSP
349 #   endif /* NUMCC <= VSUSP */
350 #  endif /* VSUSP */
351 #  ifdef VDSUSP
352 #   if NUMCC <= VDSUSP
353 #    undef VDSUSP
354 #   endif /* NUMCC <= VDSUSP */
355 #  endif /* VDSUSP */
356 #  ifdef VREPRINT
357 #   if NUMCC <= VREPRINT
358 #    undef VREPRINT
359 #   endif /* NUMCC <= VREPRINT */
360 #  endif /* VREPRINT */
361 #  ifdef VDISCARD
362 #   if NUMCC <= VDISCARD
363 #    undef VDISCARD
364 #   endif /* NUMCC <= VDISCARD */
365 #  endif /* VDISCARD */
366 #  ifdef VLNEXT
367 #   if NUMCC <= VLNEXT
368 #    undef VLNEXT
369 #   endif /* NUMCC <= VLNEXT */
370 #  endif /* VLNEXT */
371 #  ifdef VSTATUS
372 #   if NUMCC <= VSTATUS
373 #    undef VSTATUS
374 #   endif /* NUMCC <= VSTATUS */
375 #  endif /* VSTATUS */
376 #  ifdef VPAGE
377 #   if NUMCC <= VPAGE
378 #    undef VPAGE
379 #   endif /* NUMCC <= VPAGE */
380 #  endif /* VPAGE */
381 #  ifdef VPGOFF
382 #   if NUMCC <= VPGOFF
383 #    undef VPGOFF
384 #   endif /* NUMCC <= VPGOFF */
385 #  endif /* VPGOFF */
386 #  ifdef VKILL2
387 #   if NUMCC <= VKILL2
388 #    undef VKILL2
389 #   endif /* NUMCC <= VKILL2 */
390 #  endif /* VKILL2 */
391 #  ifdef VBRK
392 #   if NUMCC <= VBRK
393 #    undef VBRK
394 #   endif /* NUMCC <= VBRK */
395 #  endif /* VBRK */
396 #  ifdef VMIN
397 #   if NUMCC <= VMIN
398 #    undef VMIN
399 #   endif /* NUMCC <= VMIN */
400 #  endif /* VMIN */
401 #  ifdef VTIME
402 #   if NUMCC <= VTIME
403 #    undef VTIME
404 #   endif /* NUMCC <= VTIME */
405 #  endif /* VTIME */
406 # endif /* NUMCC */
407 #endif /* !POSIX */
408
409 #define C_INTR           0
410 #define C_QUIT           1
411 #define C_ERASE          2
412 #define C_KILL           3
413 #define C_EOF            4
414 #define C_EOL            5
415 #define C_EOL2           6
416 #define C_SWTCH          7
417 #define C_DSWTCH         8
418 #define C_ERASE2         9
419 #define C_START         10
420 #define C_STOP          11
421 #define C_WERASE        12
422 #define C_SUSP          13
423 #define C_DSUSP         14
424 #define C_REPRINT       15
425 #define C_DISCARD       16
426 #define C_LNEXT         17
427 #define C_STATUS        18
428 #define C_PAGE          19
429 #define C_PGOFF         20
430 #define C_KILL2         21
431 #define C_BRK           22
432 #define C_MIN           23
433 #define C_TIME          24
434 #define C_NCC           25
435 #define C_SH(A)         (1 << (A))
436
437 /*
438  * Terminal dependend data structures
439  */
440 #define EX_IO   0       /* while we are executing       */
441 #define ED_IO   1       /* while we are editing         */
442 #define TS_IO   2       /* new mode from terminal       */
443 #define QU_IO   2       /* used only for quoted chars   */
444 #define NN_IO   3       /* The number of entries        */
445
446 #define M_INP   0
447 #define M_OUT   1
448 #define M_CTL   2
449 #define M_LIN   3
450 #define M_CHAR  4
451 #define M_NN    5
452
453 typedef struct {
454     char *t_name;
455     u_int t_setmask;
456     u_int t_clrmask;
457 } ttyperm_t[NN_IO][M_NN];
458
459 typedef unsigned char ttychar_t[NN_IO][C_NCC];
460
461 protected int   tty_init        (EditLine *);
462 protected void  tty_end         (EditLine *);
463 protected int   tty_stty        (EditLine *, int, char**);
464 protected int   tty_rawmode     (EditLine *);
465 protected int   tty_cookedmode  (EditLine *);
466 protected int   tty_quotemode   (EditLine *);
467 protected int   tty_noquotemode (EditLine *);
468 protected void  tty_bind_char   (EditLine *, int);
469
470 typedef struct {
471     ttyperm_t t_t;
472     ttychar_t t_c;
473     struct termios t_ex, t_ed, t_ts;
474     int t_tabs;
475     int t_eight;
476     speed_t t_speed;
477     int t_mode;
478     unsigned char t_vdisable;
479 } el_tty_t;
480
481
482 #endif /* _h_el_tty */