1 /****************************************************************************
2 * Copyright (c) 1998-2012,2016 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.22 2016/05/28 23:22:52 tom Exp $")
55 #include <sys/termio.h> /* needed for ISC */
60 #define _nc_setmode(mode) setmode(SP_PARM->_ifd, mode)
62 #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)
86 T((T_CALLED("raw(%p)"), (void *) SP_PARM));
87 if ((termp = TerminalOf(SP_PARM)) != 0) {
91 _nc_setmode(O_BINARY);
95 buf.c_lflag &= (unsigned) ~(ICANON | ISIG | IEXTEN);
96 buf.c_iflag &= (unsigned) ~(COOKED_INPUT);
102 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
107 kbdinfo.cb = sizeof(kbdinfo);
108 KbdGetStatus(&kbdinfo, 0);
110 kbdinfo.cb = sizeof(kbdinfo);
111 kbdinfo.fsMask &= ~KEYBOARD_ASCII_MODE;
112 kbdinfo.fsMask |= KEYBOARD_BINARY_MODE;
113 KbdSetStatus(&kbdinfo, 0);
115 SP_PARM->_raw = TRUE;
116 SP_PARM->_cbreak = 1;
128 return NCURSES_SP_NAME(raw) (CURRENT_SCREEN);
133 NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
138 T((T_CALLED("cbreak(%p)"), (void *) SP_PARM));
139 if ((termp = TerminalOf(SP_PARM)) != 0) {
143 _nc_setmode(O_BINARY);
147 buf.c_lflag &= (unsigned) ~ICANON;
148 buf.c_iflag &= (unsigned) ~ICRNL;
153 buf.sg_flags |= CBREAK;
155 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
157 SP_PARM->_cbreak = 1;
169 return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN);
175 * this implementation may be wrong. See the comment under intrflush().
178 NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
182 T((T_CALLED("qiflush(%p)"), (void *) SP_PARM));
183 if ((termp = TerminalOf(SP_PARM)) != 0) {
190 buf.c_lflag &= (unsigned) ~(NOFLSH);
191 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
207 NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN);
212 NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
217 T((T_CALLED("noraw(%p)"), (void *) SP_PARM));
218 if ((termp = TerminalOf(SP_PARM)) != 0) {
226 buf.c_lflag |= ISIG | ICANON |
227 (termp->Ottyb.c_lflag & IEXTEN);
228 buf.c_iflag |= COOKED_INPUT;
230 buf.sg_flags &= ~(RAW | CBREAK);
232 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
237 kbdinfo.cb = sizeof(kbdinfo);
238 KbdGetStatus(&kbdinfo, 0);
240 kbdinfo.cb = sizeof(kbdinfo);
241 kbdinfo.fsMask &= ~KEYBOARD_BINARY_MODE;
242 kbdinfo.fsMask |= KEYBOARD_ASCII_MODE;
243 KbdSetStatus(&kbdinfo, 0);
245 SP_PARM->_raw = FALSE;
246 SP_PARM->_cbreak = 0;
258 return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN);
263 NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
268 T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM));
269 if ((termp = TerminalOf(SP_PARM)) != 0) {
277 buf.c_lflag |= ICANON;
278 buf.c_iflag |= ICRNL;
280 buf.sg_flags &= ~CBREAK;
282 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
284 SP_PARM->_cbreak = 0;
296 return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN);
301 NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
305 T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM));
306 if ((termp = TerminalOf(SP_PARM)) != 0) {
313 buf.c_lflag |= NOFLSH;
314 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
330 NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN);
335 * This call does the same thing as the qiflush()/noqiflush() pair. We know
336 * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
337 * the match (in the SVr4 man pages) between the language describing NOFLSH in
338 * termio(7) and the language describing qiflush()/noqiflush() in
339 * curs_inopts(3x) is too exact to be coincidence.
342 NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag)
347 T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM, flag));
351 if ((termp = TerminalOf(SP_PARM)) != 0) {
358 buf.c_lflag &= (unsigned) ~(NOFLSH);
360 buf.c_lflag |= (NOFLSH);
361 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
375 intrflush(WINDOW *win GCC_UNUSED, bool flag)
377 return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag);