1 /****************************************************************************
2 * Copyright (c) 1998-2007,2009 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 * and: Juergen Pfeifer 2009 *
34 ****************************************************************************/
50 #include <curses.priv.h>
51 #include <term.h> /* cur_term */
53 MODULE_ID("$Id: lib_raw.c,v 1.15 2009/02/15 00:49:02 tom Exp $")
55 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
60 #include <sys/termio.h> /* needed for ISC */
65 #define _nc_setmode(mode) setmode(SP_PARM->_ifd, mode)
67 #define _nc_setmode(mode) /* nothing */
70 #define COOKED_INPUT (IXON|BRKINT|PARMRK)
73 #define BEFORE(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits())
74 #define AFTER(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits())
81 NCURSES_SP_NAME(raw) (NCURSES_SP_DCL0)
85 T((T_CALLED("raw()")));
87 if (SP_PARM != 0 && cur_term != 0) {
91 _nc_setmode(O_BINARY);
93 buf = cur_term->Nttyb;
95 buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
96 buf.c_iflag &= ~(COOKED_INPUT);
102 if ((result = _nc_set_tty_mode(&buf)) == OK) {
103 SP_PARM->_raw = TRUE;
104 SP_PARM->_cbreak = 1;
105 cur_term->Nttyb = buf;
116 return NCURSES_SP_NAME(raw) (CURRENT_SCREEN);
121 NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
125 T((T_CALLED("cbreak()")));
127 if (SP_PARM != 0 && cur_term != 0) {
131 _nc_setmode(O_BINARY);
133 buf = cur_term->Nttyb;
135 buf.c_lflag &= ~ICANON;
136 buf.c_iflag &= ~ICRNL;
141 buf.sg_flags |= CBREAK;
143 if ((result = _nc_set_tty_mode(&buf)) == OK) {
144 SP_PARM->_cbreak = 1;
145 cur_term->Nttyb = buf;
156 return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN);
162 * this implementation may be wrong. See the comment under intrflush().
165 NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
169 T((T_CALLED("qiflush()")));
175 buf = cur_term->Nttyb;
177 buf.c_lflag &= ~(NOFLSH);
178 result = _nc_set_tty_mode(&buf);
183 cur_term->Nttyb = buf;
193 NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN);
198 NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
202 T((T_CALLED("noraw()")));
204 if (SP_PARM != 0 && cur_term != 0) {
210 buf = cur_term->Nttyb;
212 buf.c_lflag |= ISIG | ICANON |
213 (cur_term->Ottyb.c_lflag & IEXTEN);
214 buf.c_iflag |= COOKED_INPUT;
216 buf.sg_flags &= ~(RAW | CBREAK);
218 if ((result = _nc_set_tty_mode(&buf)) == OK) {
219 SP_PARM->_raw = FALSE;
220 SP_PARM->_cbreak = 0;
221 cur_term->Nttyb = buf;
232 return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN);
237 NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
241 T((T_CALLED("nocbreak()")));
243 if (SP_PARM != 0 && cur_term != 0) {
249 buf = cur_term->Nttyb;
251 buf.c_lflag |= ICANON;
252 buf.c_iflag |= ICRNL;
254 buf.sg_flags &= ~CBREAK;
256 if ((result = _nc_set_tty_mode(&buf)) == OK) {
257 SP_PARM->_cbreak = 0;
258 cur_term->Nttyb = buf;
269 return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN);
275 * this implementation may be wrong. See the comment under intrflush().
278 NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
282 T((T_CALLED("noqiflush()")));
288 buf = cur_term->Nttyb;
290 buf.c_lflag |= NOFLSH;
291 result = _nc_set_tty_mode(&buf);
296 cur_term->Nttyb = buf;
307 NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN);
312 * This call does the same thing as the qiflush()/noqiflush() pair. We know
313 * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
314 * the match (in the SVr4 man pages) between the language describing NOFLSH in
315 * termio(7) and the language describing qiflush()/noqiflush() in
316 * curs_inopts(3x) is too exact to be coincidence.
319 NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag)
323 T((T_CALLED("intrflush(%d)"), flag));
329 buf = cur_term->Nttyb;
332 buf.c_lflag &= ~(NOFLSH);
334 buf.c_lflag |= (NOFLSH);
335 result = _nc_set_tty_mode(&buf);
340 cur_term->Nttyb = buf;
349 intrflush(WINDOW *win GCC_UNUSED, bool flag)
351 return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag);