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 ****************************************************************************/
51 #include <curses.priv.h>
52 #include <term.h> /* cur_term */
54 MODULE_ID("$Id: lib_raw.c,v 1.14 2007/09/29 21:50:22 tom Exp $")
56 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
61 #include <sys/termio.h> /* needed for ISC */
66 #define _nc_setmode(mode) setmode(SP->_ifd, mode)
68 #define _nc_setmode(mode) /* nothing */
71 #define COOKED_INPUT (IXON|BRKINT|PARMRK)
74 #define BEFORE(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits())
75 #define AFTER(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits())
86 T((T_CALLED("raw()")));
88 if (SP != 0 && cur_term != 0) {
92 _nc_setmode(O_BINARY);
94 buf = cur_term->Nttyb;
96 buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
97 buf.c_iflag &= ~(COOKED_INPUT);
103 if ((result = _nc_set_tty_mode(&buf)) == OK) {
106 cur_term->Nttyb = buf;
118 T((T_CALLED("cbreak()")));
120 if (SP != 0 && cur_term != 0) {
124 _nc_setmode(O_BINARY);
126 buf = cur_term->Nttyb;
128 buf.c_lflag &= ~ICANON;
129 buf.c_iflag &= ~ICRNL;
134 buf.sg_flags |= CBREAK;
136 if ((result = _nc_set_tty_mode(&buf)) == OK) {
138 cur_term->Nttyb = buf;
147 * this implementation may be wrong. See the comment under intrflush().
154 T((T_CALLED("qiflush()")));
160 buf = cur_term->Nttyb;
162 buf.c_lflag &= ~(NOFLSH);
163 result = _nc_set_tty_mode(&buf);
168 cur_term->Nttyb = buf;
179 T((T_CALLED("noraw()")));
181 if (SP != 0 && cur_term != 0) {
187 buf = cur_term->Nttyb;
189 buf.c_lflag |= ISIG | ICANON |
190 (cur_term->Ottyb.c_lflag & IEXTEN);
191 buf.c_iflag |= COOKED_INPUT;
193 buf.sg_flags &= ~(RAW | CBREAK);
195 if ((result = _nc_set_tty_mode(&buf)) == OK) {
198 cur_term->Nttyb = buf;
210 T((T_CALLED("nocbreak()")));
212 if (SP != 0 && cur_term != 0) {
218 buf = cur_term->Nttyb;
220 buf.c_lflag |= ICANON;
221 buf.c_iflag |= ICRNL;
223 buf.sg_flags &= ~CBREAK;
225 if ((result = _nc_set_tty_mode(&buf)) == OK) {
227 cur_term->Nttyb = buf;
236 * this implementation may be wrong. See the comment under intrflush().
243 T((T_CALLED("noqiflush()")));
249 buf = cur_term->Nttyb;
251 buf.c_lflag |= NOFLSH;
252 result = _nc_set_tty_mode(&buf);
257 cur_term->Nttyb = buf;
265 * This call does the same thing as the qiflush()/noqiflush() pair. We know
266 * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
267 * the match (in the SVr4 man pages) between the language describing NOFLSH in
268 * termio(7) and the language describing qiflush()/noqiflush() in
269 * curs_inopts(3x) is too exact to be coincidence.
272 intrflush(WINDOW *win GCC_UNUSED, bool flag)
276 T((T_CALLED("intrflush(%d)"), flag));
282 buf = cur_term->Nttyb;
285 buf.c_lflag &= ~(NOFLSH);
287 buf.c_lflag |= (NOFLSH);
288 result = _nc_set_tty_mode(&buf);
293 cur_term->Nttyb = buf;