1 /***********************************************************************
2  *                                                                      *
3  *               This software is part of the ast package               *
4  *          Copyright (c) 1982-2012 AT&T Intellectual Property          *
5  *                      and is licensed under the                       *
6  *                 Eclipse Public License, Version 1.0                  *
7  *                    by AT&T Intellectual Property                     *
8  *                                                                      *
9  *                A copy of the License is available at                 *
10  *          http://www.eclipse.org/org/documents/epl-v10.html           *
11  *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12  *                                                                      *
13  *              Information and Software Systems Research               *
14  *                            AT&T Research                             *
15  *                           Florham Park NJ                            *
16  *                                                                      *
17  *                    David Korn <dgkorn@gmail.com>                     *
18  *                                                                      *
19  ***********************************************************************/
20 #ifndef _TERMINAL_H
21 #define _TERMINAL_H 1
22 
23 //
24 // Terminal interface is complicated by the fact that there are so many variations. This will use
25 // POSIX <termios.h> interface where available.
26 //
27 #include <termios.h>
28 
29 #undef tcgetattr
30 #undef tcsetattr
31 // The following corrects bugs in some implementations.
32 #if defined(TCSADFLUSH) && !defined(TCSAFLUSH)
33 #define TCSAFLUSH TCSADFLUSH
34 #endif  // TCSADFLUSH
35 #undef TIOCGETC
36 
37 // Set ECHOCTL if driver can echo control charaters as ^c.
38 #ifdef LCTLECH
39 #ifndef ECHOCTL
40 #define ECHOCTL LCTLECH
41 #endif  // !ECHOCTL
42 #endif  // LCTLECH
43 #ifdef LNEW_CTLECH
44 #ifndef ECHOCTL
45 #define ECHOCTL LNEW_CTLECH
46 #endif  // !ECHOCTL
47 #endif  // LNEW_CTLECH
48 #ifdef LNEW_PENDIN
49 #ifndef PENDIN
50 #define PENDIN LNEW_PENDIN
51 #endif  // !PENDIN
52 #endif  // LNEW_PENDIN
53 #ifndef ECHOCTL
54 #ifndef VEOL
55 #endif  // !VEOL
56 #endif  // !ECHOCTL
57 
58 #if _hdr_sys_filio
59 #include <sys/filio.h>
60 #endif  // _sys_filio
61 
62 // This symbol is used by the CLI editor modes to signal an invalid character.
63 // Why it is U+DFFF (the last char in the low-surrogate range) is a mystery.
64 // There are other Unicode codepoints that would seem more appropriate.
65 // For example, U+FFFF or U+FFFE.
66 #define MARKER 0xdfff  // must be an invalid character
67 
68 extern void tty_cooked(int);
69 extern int tty_get(int, struct termios *);
70 extern int tty_raw(int, int);
71 extern int tty_check(int);
72 extern int tty_set(int, int, struct termios *);
73 
74 extern int sh_tcgetattr(int, struct termios *);
75 extern int sh_tcsetattr(int, int, struct termios *);
76 #define tcgetattr(a, b) sh_tcgetattr(a, b)
77 #define tcsetattr(a, b, c) sh_tcsetattr(a, b, c)
78 
79 #endif  // _TERMINAL_H
80