1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
32 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
33 * and: Thomas E. Dickey 1998-on *
34 * and: Juergen Pfeifer 2009 *
35 ****************************************************************************/
51 #include <curses.priv.h>
53 MODULE_ID("$Id: lib_raw.c,v 1.24 2020/02/02 23:34:34 tom Exp $")
56 #include <sys/termio.h> /* needed for ISC */
61 #define _nc_setmode(mode) setmode(SP_PARM->_ifd, mode)
63 #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())
82 NCURSES_SP_NAME(raw) (NCURSES_SP_DCL0)
87 T((T_CALLED("raw(%p)"), (void *) SP_PARM));
88 if ((termp = TerminalOf(SP_PARM)) != 0) {
92 _nc_setmode(O_BINARY);
96 buf.c_lflag &= (unsigned) ~(ICANON | ISIG | IEXTEN);
97 buf.c_iflag &= (unsigned) ~(COOKED_INPUT);
103 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
108 kbdinfo.cb = sizeof(kbdinfo);
109 KbdGetStatus(&kbdinfo, 0);
111 kbdinfo.cb = sizeof(kbdinfo);
112 kbdinfo.fsMask &= ~KEYBOARD_ASCII_MODE;
113 kbdinfo.fsMask |= KEYBOARD_BINARY_MODE;
114 KbdSetStatus(&kbdinfo, 0);
117 SP_PARM->_raw = TRUE;
118 SP_PARM->_cbreak = 1;
131 return NCURSES_SP_NAME(raw) (CURRENT_SCREEN);
136 NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0)
141 T((T_CALLED("cbreak(%p)"), (void *) SP_PARM));
142 if ((termp = TerminalOf(SP_PARM)) != 0) {
146 _nc_setmode(O_BINARY);
150 buf.c_lflag &= (unsigned) ~ICANON;
151 buf.c_iflag &= (unsigned) ~ICRNL;
156 buf.sg_flags |= CBREAK;
158 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
161 SP_PARM->_cbreak = 1;
174 return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN);
180 * this implementation may be wrong. See the comment under intrflush().
183 NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0)
187 T((T_CALLED("qiflush(%p)"), (void *) SP_PARM));
188 if ((termp = TerminalOf(SP_PARM)) != 0) {
195 buf.c_lflag &= (unsigned) ~(NOFLSH);
196 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
212 NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN);
217 NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0)
222 T((T_CALLED("noraw(%p)"), (void *) SP_PARM));
223 if ((termp = TerminalOf(SP_PARM)) != 0) {
231 buf.c_lflag |= ISIG | ICANON |
232 (termp->Ottyb.c_lflag & IEXTEN);
233 buf.c_iflag |= COOKED_INPUT;
235 buf.sg_flags &= ~(RAW | CBREAK);
237 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
242 kbdinfo.cb = sizeof(kbdinfo);
243 KbdGetStatus(&kbdinfo, 0);
245 kbdinfo.cb = sizeof(kbdinfo);
246 kbdinfo.fsMask &= ~KEYBOARD_BINARY_MODE;
247 kbdinfo.fsMask |= KEYBOARD_ASCII_MODE;
248 KbdSetStatus(&kbdinfo, 0);
251 SP_PARM->_raw = FALSE;
252 SP_PARM->_cbreak = 0;
265 return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN);
270 NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0)
275 T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM));
276 if ((termp = TerminalOf(SP_PARM)) != 0) {
284 buf.c_lflag |= ICANON;
285 buf.c_iflag |= ICRNL;
287 buf.sg_flags &= ~CBREAK;
289 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
292 SP_PARM->_cbreak = 0;
305 return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN);
310 NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0)
314 T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM));
315 if ((termp = TerminalOf(SP_PARM)) != 0) {
322 buf.c_lflag |= NOFLSH;
323 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
339 NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN);
344 * This call does the same thing as the qiflush()/noqiflush() pair. We know
345 * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand,
346 * the match (in the SVr4 man pages) between the language describing NOFLSH in
347 * termio(7) and the language describing qiflush()/noqiflush() in
348 * curs_inopts(3x) is too exact to be coincidence.
351 NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag)
356 T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM, flag));
360 if ((termp = TerminalOf(SP_PARM)) != 0) {
367 buf.c_lflag &= (unsigned) ~(NOFLSH);
369 buf.c_lflag |= (NOFLSH);
370 result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf);
384 intrflush(WINDOW *win GCC_UNUSED, bool flag)
386 return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag);