]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_raw.c
ncurses 5.2
[ncurses.git] / ncurses / tinfo / lib_raw.c
1 /****************************************************************************
2  * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
3  *                                                                          *
4  * Permission is hereby granted, free of charge, to any person obtaining a  *
5  * copy of this software and associated documentation files (the            *
6  * "Software"), to deal in the Software without restriction, including      *
7  * without limitation the rights to use, copy, modify, merge, publish,      *
8  * distribute, distribute with modifications, sublicense, and/or sell       *
9  * copies of the Software, and to permit persons to whom the Software is    *
10  * furnished to do so, subject to the following conditions:                 *
11  *                                                                          *
12  * The above copyright notice and this permission notice shall be included  *
13  * in all copies or substantial portions of the Software.                   *
14  *                                                                          *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
16  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
18  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
19  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
20  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
21  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
22  *                                                                          *
23  * Except as contained in this notice, the name(s) of the above copyright   *
24  * holders shall not be used in advertising or otherwise to promote the     *
25  * sale, use or other dealings in this Software without prior written       *
26  * authorization.                                                           *
27  ****************************************************************************/
28
29 /****************************************************************************
30  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33
34 /*
35  *      raw.c
36  *
37  *      Routines:
38  *              raw()
39  *              cbreak()
40  *              noraw()
41  *              nocbreak()
42  *              qiflush()
43  *              noqiflush()
44  *              intrflush()
45  *
46  */
47
48 #include <curses.priv.h>
49 #include <term.h>               /* cur_term */
50
51 MODULE_ID("$Id: lib_raw.c,v 1.8 2000/09/02 18:08:48 tom Exp $")
52
53 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
54 #define _POSIX_SOURCE
55 #endif
56
57 #if HAVE_SYS_TERMIO_H
58 #include <sys/termio.h>         /* needed for ISC */
59 #endif
60
61 #ifdef __EMX__
62 #include <io.h>
63 #endif
64
65 #define COOKED_INPUT    (IXON|BRKINT|PARMRK)
66
67 #ifdef TRACE
68 #define BEFORE(N)       if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits())
69 #define AFTER(N)        if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits())
70 #else
71 #define BEFORE(s)
72 #define AFTER(s)
73 #endif /* TRACE */
74
75 int
76 raw(void)
77 {
78     T((T_CALLED("raw()")));
79     if (SP != 0 && cur_term != 0) {
80
81         SP->_raw = TRUE;
82         SP->_cbreak = 1;
83
84 #ifdef __EMX__
85         setmode(SP->_ifd, O_BINARY);
86 #endif
87
88 #ifdef TERMIOS
89         BEFORE("raw");
90         cur_term->Nttyb.c_lflag &= ~(ICANON | ISIG | IEXTEN);
91         cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
92         cur_term->Nttyb.c_cc[VMIN] = 1;
93         cur_term->Nttyb.c_cc[VTIME] = 0;
94         AFTER("raw");
95 #else
96         cur_term->Nttyb.sg_flags |= RAW;
97 #endif
98         returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
99     }
100     returnCode(ERR);
101 }
102
103 int
104 cbreak(void)
105 {
106     T((T_CALLED("cbreak()")));
107
108     SP->_cbreak = 1;
109
110 #ifdef __EMX__
111     setmode(SP->_ifd, O_BINARY);
112 #endif
113
114 #ifdef TERMIOS
115     BEFORE("cbreak");
116     cur_term->Nttyb.c_lflag &= ~ICANON;
117     cur_term->Nttyb.c_iflag &= ~ICRNL;
118     cur_term->Nttyb.c_lflag |= ISIG;
119     cur_term->Nttyb.c_cc[VMIN] = 1;
120     cur_term->Nttyb.c_cc[VTIME] = 0;
121     AFTER("cbreak");
122 #else
123     cur_term->Nttyb.sg_flags |= CBREAK;
124 #endif
125     returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
126 }
127
128 void
129 qiflush(void)
130 {
131     T((T_CALLED("qiflush()")));
132
133     /*
134      * Note: this implementation may be wrong.  See the comment under
135      * intrflush().
136      */
137
138 #ifdef TERMIOS
139     BEFORE("qiflush");
140     cur_term->Nttyb.c_lflag &= ~(NOFLSH);
141     AFTER("qiflush");
142     (void) _nc_set_tty_mode(&cur_term->Nttyb);
143     returnVoid;
144 #endif
145 }
146
147 int
148 noraw(void)
149 {
150     T((T_CALLED("noraw()")));
151
152     SP->_raw = FALSE;
153     SP->_cbreak = 0;
154
155 #ifdef __EMX__
156     setmode(SP->_ifd, O_TEXT);
157 #endif
158
159 #ifdef TERMIOS
160     BEFORE("noraw");
161     cur_term->Nttyb.c_lflag |= ISIG | ICANON |
162         (cur_term->Ottyb.c_lflag & IEXTEN);
163     cur_term->Nttyb.c_iflag |= COOKED_INPUT;
164     AFTER("noraw");
165 #else
166     cur_term->Nttyb.sg_flags &= ~(RAW | CBREAK);
167 #endif
168     returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
169 }
170
171 int
172 nocbreak(void)
173 {
174     T((T_CALLED("nocbreak()")));
175
176     SP->_cbreak = 0;
177
178 #ifdef __EMX__
179     setmode(SP->_ifd, O_TEXT);
180 #endif
181
182 #ifdef TERMIOS
183     BEFORE("nocbreak");
184     cur_term->Nttyb.c_lflag |= ICANON;
185     cur_term->Nttyb.c_iflag |= ICRNL;
186     AFTER("nocbreak");
187 #else
188     cur_term->Nttyb.sg_flags &= ~CBREAK;
189 #endif
190     returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
191 }
192
193 void
194 noqiflush(void)
195 {
196     T((T_CALLED("noqiflush()")));
197
198     /*
199      * Note: this implementation may be wrong.  See the comment under
200      * intrflush().
201      */
202
203 #ifdef TERMIOS
204     BEFORE("noqiflush");
205     cur_term->Nttyb.c_lflag |= NOFLSH;
206     AFTER("noqiflush");
207     (void) _nc_set_tty_mode(&cur_term->Nttyb);
208     returnVoid;
209 #endif
210 }
211
212 int
213 intrflush(WINDOW *win GCC_UNUSED, bool flag)
214 {
215     T((T_CALLED("intrflush(%d)"), flag));
216
217     /*
218      * This call does the same thing as the qiflush()/noqiflush() pair.  We
219      * know for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the
220      * other hand, the match (in the SVr4 man pages) between the language
221      * describing NOFLSH in termio(7) and the language describing
222      * qiflush()/noqiflush() in curs_inopts(3x) is too exact to be coincidence.
223      */
224
225 #ifdef TERMIOS
226     BEFORE("intrflush");
227     if (flag)
228         cur_term->Nttyb.c_lflag &= ~(NOFLSH);
229     else
230         cur_term->Nttyb.c_lflag |= (NOFLSH);
231     AFTER("intrflush");
232     returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
233 #else
234     returnCode(ERR);
235 #endif
236 }