1 /****************************************************************************
2 * Copyright (c) 1998-2002,2007 Free Software Foundation, Inc. *
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: *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
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. *
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 *
27 ****************************************************************************/
29 /****************************************************************************
30 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
31 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
32 * and: Thomas E. Dickey 1998 on *
33 ****************************************************************************/
49 #include <curses.priv.h>
50 #include <term.h> /* cur_term */
52 MODULE_ID("$Id: lib_raw.c,v 1.14 2007/09/29 21:50:22 tom Exp $")
54 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
59 #include <sys/termio.h> /* needed for ISC */
64 #define _nc_setmode(mode) setmode(SP->_ifd, mode)
66 #define _nc_setmode(mode) /* nothing */
69 #define COOKED_INPUT (IXON|BRKINT|PARMRK)
72 #define BEFORE(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits())
73 #define AFTER(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits())
84 T((T_CALLED("raw()")));
86 if (SP != 0 && cur_term != 0) {
90 _nc_setmode(O_BINARY);
92 buf = cur_term->Nttyb;
94 buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
95 buf.c_iflag &= ~(COOKED_INPUT);
101 if ((result = _nc_set_tty_mode(&buf)) == OK) {
104 cur_term->Nttyb = buf;
116 T((T_CALLED("cbreak()")));
118 if (SP != 0 && cur_term != 0) {
122 _nc_setmode(O_BINARY);
124 buf = cur_term->Nttyb;
126 buf.c_lflag &= ~ICANON;
127 buf.c_iflag &= ~ICRNL;
132 buf.sg_flags |= CBREAK;
134 if ((result = _nc_set_tty_mode(&buf)) == OK) {
136 cur_term->Nttyb = buf;
145 * this implementation may be wrong. See the comment under intrflush().
152 T((T_CALLED("qiflush()")));
158 buf = cur_term->Nttyb;
160 buf.c_lflag &= ~(NOFLSH);
161 result = _nc_set_tty_mode(&buf);
166 cur_term->Nttyb = buf;
177 T((T_CALLED("noraw()")));
179 if (SP != 0 && cur_term != 0) {
185 buf = cur_term->Nttyb;
187 buf.c_lflag |= ISIG | ICANON |
188 (cur_term->Ottyb.c_lflag & IEXTEN);
189 buf.c_iflag |= COOKED_INPUT;
191 buf.sg_flags &= ~(RAW | CBREAK);
193 if ((result = _nc_set_tty_mode(&buf)) == OK) {
196 cur_term->Nttyb = buf;
208 T((T_CALLED("nocbreak()")));
210 if (SP != 0 && cur_term != 0) {
216 buf = cur_term->Nttyb;
218 buf.c_lflag |= ICANON;
219 buf.c_iflag |= ICRNL;
221 buf.sg_flags &= ~CBREAK;
223 if ((result = _nc_set_tty_mode(&buf)) == OK) {
225 cur_term->Nttyb = buf;
234 * this implementation may be wrong. See the comment under intrflush().
241 T((T_CALLED("noqiflush()")));
247 buf = cur_term->Nttyb;
249 buf.c_lflag |= NOFLSH;
250 result = _nc_set_tty_mode(&buf);
255 cur_term->Nttyb = buf;
263 * This call does the same thing as the qiflush()/noqiflush() pair. We know
264 * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
265 * the match (in the SVr4 man pages) between the language describing NOFLSH in
266 * termio(7) and the language describing qiflush()/noqiflush() in
267 * curs_inopts(3x) is too exact to be coincidence.
270 intrflush(WINDOW *win GCC_UNUSED, bool flag)
274 T((T_CALLED("intrflush(%d)"), flag));
280 buf = cur_term->Nttyb;
283 buf.c_lflag &= ~(NOFLSH);
285 buf.c_lflag |= (NOFLSH);
286 result = _nc_set_tty_mode(&buf);
291 cur_term->Nttyb = buf;