1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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>
52 MODULE_ID("$Id: lib_raw.c,v 1.19 2010/04/24 23:49:12 tom Exp $")
54 #if SVR4_TERMIO && !defined(_POSIX_SOURCE)
59 #include <sys/termio.h> /* needed for ISC */
64 #define _nc_setmode(mode) setmode(SP_PARM->_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())
80 NCURSES_SP_NAME(raw
) (NCURSES_SP_DCL0
)
85 T((T_CALLED("raw(%p)"), (void *) SP_PARM
));
86 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
90 _nc_setmode(O_BINARY
);
94 buf
.c_lflag
&= (unsigned) ~(ICANON
| ISIG
| IEXTEN
);
95 buf
.c_iflag
&= (unsigned) ~(COOKED_INPUT
);
101 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
103 SP_PARM
->_raw
= TRUE
;
104 SP_PARM
->_cbreak
= 1;
116 return NCURSES_SP_NAME(raw
) (CURRENT_SCREEN
);
121 NCURSES_SP_NAME(cbreak
) (NCURSES_SP_DCL0
)
126 T((T_CALLED("cbreak(%p)"), (void *) SP_PARM
));
127 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
131 _nc_setmode(O_BINARY
);
135 buf
.c_lflag
&= (unsigned) ~ICANON
;
136 buf
.c_iflag
&= (unsigned) ~ICRNL
;
141 buf
.sg_flags
|= CBREAK
;
143 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
145 SP_PARM
->_cbreak
= 1;
157 return NCURSES_SP_NAME(cbreak
) (CURRENT_SCREEN
);
163 * this implementation may be wrong. See the comment under intrflush().
166 NCURSES_SP_NAME(qiflush
) (NCURSES_SP_DCL0
)
171 T((T_CALLED("qiflush(%p)"), (void *) SP_PARM
));
172 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
178 buf
.c_lflag
&= (unsigned) ~(NOFLSH
);
179 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
194 NCURSES_SP_NAME(qiflush
) (CURRENT_SCREEN
);
199 NCURSES_SP_NAME(noraw
) (NCURSES_SP_DCL0
)
204 T((T_CALLED("noraw(%p)"), (void *) SP_PARM
));
205 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
213 buf
.c_lflag
|= ISIG
| ICANON
|
214 (termp
->Ottyb
.c_lflag
& IEXTEN
);
215 buf
.c_iflag
|= COOKED_INPUT
;
217 buf
.sg_flags
&= ~(RAW
| CBREAK
);
219 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
221 SP_PARM
->_raw
= FALSE
;
222 SP_PARM
->_cbreak
= 0;
234 return NCURSES_SP_NAME(noraw
) (CURRENT_SCREEN
);
239 NCURSES_SP_NAME(nocbreak
) (NCURSES_SP_DCL0
)
244 T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM
));
245 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
253 buf
.c_lflag
|= ICANON
;
254 buf
.c_iflag
|= ICRNL
;
256 buf
.sg_flags
&= ~CBREAK
;
258 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
260 SP_PARM
->_cbreak
= 0;
272 return NCURSES_SP_NAME(nocbreak
) (CURRENT_SCREEN
);
277 NCURSES_SP_NAME(noqiflush
) (NCURSES_SP_DCL0
)
282 T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM
));
283 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
289 buf
.c_lflag
|= NOFLSH
;
290 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
305 NCURSES_SP_NAME(noqiflush
) (CURRENT_SCREEN
);
310 * This call does the same thing as the qiflush()/noqiflush() pair. We know
311 * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
312 * the match (in the SVr4 man pages) between the language describing NOFLSH in
313 * termio(7) and the language describing qiflush()/noqiflush() in
314 * curs_inopts(3x) is too exact to be coincidence.
317 NCURSES_SP_NAME(intrflush
) (NCURSES_SP_DCLx WINDOW
*win GCC_UNUSED
, bool flag
)
322 T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM
, flag
));
326 if ((termp
= TerminalOf(SP_PARM
)) != 0) {
333 buf
.c_lflag
&= (unsigned) ~(NOFLSH
);
335 buf
.c_lflag
|= (NOFLSH
);
336 result
= NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
&buf
);
350 intrflush(WINDOW
*win GCC_UNUSED
, bool flag
)
352 return NCURSES_SP_NAME(intrflush
) (CURRENT_SCREEN
, win
, flag
);