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