Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2020-2023,2024 Thomas E. Dickey * |
| 3 | * Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 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: * |
| 12 | * * |
| 13 | * The above copyright notice and this permission notice shall be included * |
| 14 | * in all copies or substantial portions of the Software. * |
| 15 | * * |
| 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. * |
| 23 | * * |
| 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 * |
| 27 | * authorization. * |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | /**************************************************************************** |
| 31 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 32 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 33 | * and: Thomas E. Dickey 1998-on * |
| 34 | * and: Juergen Pfeifer 2009 * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 35 | ****************************************************************************/ |
| 36 | |
| 37 | /* |
| 38 | * raw.c |
| 39 | * |
| 40 | * Routines: |
| 41 | * raw() |
| 42 | * cbreak() |
| 43 | * noraw() |
| 44 | * nocbreak() |
| 45 | * qiflush() |
| 46 | * noqiflush() |
| 47 | * intrflush() |
| 48 | * |
| 49 | */ |
| 50 | |
| 51 | #include <curses.priv.h> |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 52 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 53 | MODULE_ID("$Id: lib_raw.c,v 1.30 2024/03/30 15:54:17 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 54 | |
| 55 | #if HAVE_SYS_TERMIO_H |
| 56 | #include <sys/termio.h> /* needed for ISC */ |
| 57 | #endif |
| 58 | |
| 59 | #ifdef __EMX__ |
| 60 | #include <io.h> |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 61 | #define _nc_setmode(mode) setmode(SP_PARM->_ifd, mode) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 62 | #else |
| 63 | #define _nc_setmode(mode) /* nothing */ |
| 64 | #endif |
| 65 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 66 | #if USE_KLIBC_KBD |
| 67 | #define INCL_KBD |
| 68 | #include <os2.h> |
| 69 | #endif |
| 70 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 71 | #define COOKED_INPUT (IXON|BRKINT|PARMRK) |
| 72 | |
| 73 | #ifdef TRACE |
| 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()) |
| 76 | #else |
| 77 | #define BEFORE(s) |
| 78 | #define AFTER(s) |
| 79 | #endif /* TRACE */ |
| 80 | |
| 81 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 82 | NCURSES_SP_NAME(raw) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 83 | { |
| 84 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 85 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 86 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 87 | T((T_CALLED("raw(%p)"), (void *) SP_PARM)); |
| 88 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 89 | TTY buf; |
| 90 | |
| 91 | BEFORE("raw"); |
| 92 | _nc_setmode(O_BINARY); |
| 93 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 94 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 95 | #ifdef TERMIOS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 96 | buf.c_lflag &= (unsigned) ~(ICANON | ISIG | IEXTEN); |
| 97 | buf.c_iflag &= (unsigned) ~(COOKED_INPUT); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 98 | buf.c_cc[VMIN] = 1; |
| 99 | buf.c_cc[VTIME] = 0; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 100 | #elif defined(EXP_WIN32_DRIVER) |
| 101 | buf.dwFlagIn &= (unsigned long) ~CONMODE_NORAW; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 102 | #else |
| 103 | buf.sg_flags |= RAW; |
| 104 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 105 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
| 106 | if (result == OK) { |
| 107 | #if USE_KLIBC_KBD |
| 108 | KBDINFO kbdinfo; |
| 109 | |
| 110 | kbdinfo.cb = sizeof(kbdinfo); |
| 111 | KbdGetStatus(&kbdinfo, 0); |
| 112 | |
| 113 | kbdinfo.cb = sizeof(kbdinfo); |
| 114 | kbdinfo.fsMask &= ~KEYBOARD_ASCII_MODE; |
| 115 | kbdinfo.fsMask |= KEYBOARD_BINARY_MODE; |
| 116 | KbdSetStatus(&kbdinfo, 0); |
| 117 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 118 | if (SP_PARM) { |
| 119 | IsRaw(SP_PARM) = TRUE; |
| 120 | IsCbreak(SP_PARM) = 1; |
| 121 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 122 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 123 | } |
| 124 | AFTER("raw"); |
| 125 | } |
| 126 | returnCode(result); |
| 127 | } |
| 128 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 129 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 130 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 131 | raw(void) |
| 132 | { |
| 133 | return NCURSES_SP_NAME(raw) (CURRENT_SCREEN); |
| 134 | } |
| 135 | #endif |
| 136 | |
| 137 | NCURSES_EXPORT(int) |
| 138 | NCURSES_SP_NAME(cbreak) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 139 | { |
| 140 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 141 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 142 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 143 | T((T_CALLED("cbreak(%p)"), (void *) SP_PARM)); |
| 144 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 145 | TTY buf; |
| 146 | |
| 147 | BEFORE("cbreak"); |
| 148 | _nc_setmode(O_BINARY); |
| 149 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 150 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 151 | #ifdef TERMIOS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 152 | buf.c_lflag &= (unsigned) ~ICANON; |
| 153 | buf.c_iflag &= (unsigned) ~ICRNL; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 154 | buf.c_cc[VMIN] = 1; |
| 155 | buf.c_cc[VTIME] = 0; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 156 | #elif defined(EXP_WIN32_DRIVER) |
| 157 | buf.dwFlagIn |= CONMODE_NORAW; |
| 158 | buf.dwFlagIn &= (unsigned long) ~CONMODE_NOCBREAK; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 159 | #else |
| 160 | buf.sg_flags |= CBREAK; |
| 161 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 162 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
| 163 | if (result == OK) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 164 | if (SP_PARM) { |
| 165 | IsCbreak(SP_PARM) = 1; |
| 166 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 167 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 168 | } |
| 169 | AFTER("cbreak"); |
| 170 | } |
| 171 | returnCode(result); |
| 172 | } |
| 173 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 174 | #if NCURSES_SP_FUNCS |
| 175 | NCURSES_EXPORT(int) |
| 176 | cbreak(void) |
| 177 | { |
| 178 | return NCURSES_SP_NAME(cbreak) (CURRENT_SCREEN); |
| 179 | } |
| 180 | #endif |
| 181 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 182 | /* |
| 183 | * Note: |
| 184 | * this implementation may be wrong. See the comment under intrflush(). |
| 185 | */ |
| 186 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 187 | NCURSES_SP_NAME(qiflush) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 188 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 189 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 190 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 191 | T((T_CALLED("qiflush(%p)"), (void *) SP_PARM)); |
| 192 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 193 | TTY buf; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 194 | int result; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 195 | |
| 196 | BEFORE("qiflush"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 197 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 198 | #ifdef TERMIOS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 199 | buf.c_lflag &= (unsigned) ~(NOFLSH); |
| 200 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 201 | #else |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 202 | result = ERR; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 203 | /* FIXME */ |
| 204 | #endif |
| 205 | if (result == OK) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 206 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 207 | AFTER("qiflush"); |
| 208 | } |
| 209 | returnVoid; |
| 210 | } |
| 211 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 212 | #if NCURSES_SP_FUNCS |
| 213 | NCURSES_EXPORT(void) |
| 214 | qiflush(void) |
| 215 | { |
| 216 | NCURSES_SP_NAME(qiflush) (CURRENT_SCREEN); |
| 217 | } |
| 218 | #endif |
| 219 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 220 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 221 | NCURSES_SP_NAME(noraw) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 222 | { |
| 223 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 224 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 225 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 226 | T((T_CALLED("noraw(%p)"), (void *) SP_PARM)); |
| 227 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 228 | TTY buf; |
| 229 | |
| 230 | BEFORE("noraw"); |
| 231 | _nc_setmode(O_TEXT); |
| 232 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 233 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 234 | #ifdef TERMIOS |
| 235 | buf.c_lflag |= ISIG | ICANON | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 236 | (termp->Ottyb.c_lflag & IEXTEN); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 237 | buf.c_iflag |= COOKED_INPUT; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 238 | #elif defined(EXP_WIN32_DRIVER) |
| 239 | buf.dwFlagIn |= CONMODE_NORAW; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 240 | #else |
| 241 | buf.sg_flags &= ~(RAW | CBREAK); |
| 242 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 243 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
| 244 | if (result == OK) { |
| 245 | #if USE_KLIBC_KBD |
| 246 | KBDINFO kbdinfo; |
| 247 | |
| 248 | kbdinfo.cb = sizeof(kbdinfo); |
| 249 | KbdGetStatus(&kbdinfo, 0); |
| 250 | |
| 251 | kbdinfo.cb = sizeof(kbdinfo); |
| 252 | kbdinfo.fsMask &= ~KEYBOARD_BINARY_MODE; |
| 253 | kbdinfo.fsMask |= KEYBOARD_ASCII_MODE; |
| 254 | KbdSetStatus(&kbdinfo, 0); |
| 255 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 256 | if (SP_PARM) { |
| 257 | IsRaw(SP_PARM) = FALSE; |
| 258 | IsCbreak(SP_PARM) = 0; |
| 259 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 260 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 261 | } |
| 262 | AFTER("noraw"); |
| 263 | } |
| 264 | returnCode(result); |
| 265 | } |
| 266 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 267 | #if NCURSES_SP_FUNCS |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 268 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 269 | noraw(void) |
| 270 | { |
| 271 | return NCURSES_SP_NAME(noraw) (CURRENT_SCREEN); |
| 272 | } |
| 273 | #endif |
| 274 | |
| 275 | NCURSES_EXPORT(int) |
| 276 | NCURSES_SP_NAME(nocbreak) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 277 | { |
| 278 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 279 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 280 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 281 | T((T_CALLED("nocbreak(%p)"), (void *) SP_PARM)); |
| 282 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 283 | TTY buf; |
| 284 | |
| 285 | BEFORE("nocbreak"); |
| 286 | _nc_setmode(O_TEXT); |
| 287 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 288 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 289 | #ifdef TERMIOS |
| 290 | buf.c_lflag |= ICANON; |
| 291 | buf.c_iflag |= ICRNL; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 292 | #elif defined(EXP_WIN32_DRIVER) |
| 293 | buf.dwFlagIn |= (CONMODE_NOCBREAK | CONMODE_NORAW); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 294 | #else |
| 295 | buf.sg_flags &= ~CBREAK; |
| 296 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 297 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
| 298 | if (result == OK) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 299 | if (SP_PARM) { |
| 300 | IsCbreak(SP_PARM) = 0; |
| 301 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 302 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 303 | } |
| 304 | AFTER("nocbreak"); |
| 305 | } |
| 306 | returnCode(result); |
| 307 | } |
| 308 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 309 | #if NCURSES_SP_FUNCS |
| 310 | NCURSES_EXPORT(int) |
| 311 | nocbreak(void) |
| 312 | { |
| 313 | return NCURSES_SP_NAME(nocbreak) (CURRENT_SCREEN); |
| 314 | } |
| 315 | #endif |
| 316 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 317 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 318 | NCURSES_SP_NAME(noqiflush) (NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 319 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 320 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 321 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 322 | T((T_CALLED("noqiflush(%p)"), (void *) SP_PARM)); |
| 323 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 324 | TTY buf; |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 325 | int result; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 326 | |
| 327 | BEFORE("noqiflush"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 328 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 329 | #ifdef TERMIOS |
| 330 | buf.c_lflag |= NOFLSH; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 331 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 332 | #else |
| 333 | /* FIXME */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 334 | result = ERR; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 335 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 336 | if (result == OK) |
| 337 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 338 | AFTER("noqiflush"); |
| 339 | } |
| 340 | returnVoid; |
| 341 | } |
| 342 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 343 | #if NCURSES_SP_FUNCS |
| 344 | NCURSES_EXPORT(void) |
| 345 | noqiflush(void) |
| 346 | { |
| 347 | NCURSES_SP_NAME(noqiflush) (CURRENT_SCREEN); |
| 348 | } |
| 349 | #endif |
| 350 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 351 | /* |
| 352 | * This call does the same thing as the qiflush()/noqiflush() pair. We know |
| 353 | * for certain that SVr3 intrflush() tweaks the NOFLSH bit; on the other hand, |
| 354 | * the match (in the SVr4 man pages) between the language describing NOFLSH in |
| 355 | * termio(7) and the language describing qiflush()/noqiflush() in |
| 356 | * curs_inopts(3x) is too exact to be coincidence. |
| 357 | */ |
| 358 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 359 | NCURSES_SP_NAME(intrflush) (NCURSES_SP_DCLx WINDOW *win GCC_UNUSED, bool flag) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 360 | { |
| 361 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 362 | TERMINAL *termp; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 363 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 364 | T((T_CALLED("intrflush(%p,%d)"), (void *) SP_PARM, flag)); |
| 365 | if (SP_PARM == 0) |
| 366 | returnCode(ERR); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 367 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 368 | if ((termp = TerminalOf(SP_PARM)) != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 369 | TTY buf; |
| 370 | |
| 371 | BEFORE("intrflush"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 372 | buf = termp->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 373 | #ifdef TERMIOS |
| 374 | if (flag) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 375 | buf.c_lflag &= (unsigned) ~(NOFLSH); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 376 | else |
| 377 | buf.c_lflag |= (NOFLSH); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 378 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 379 | #else |
| 380 | /* FIXME */ |
| 381 | #endif |
| 382 | if (result == OK) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 383 | termp->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 384 | } |
| 385 | AFTER("intrflush"); |
| 386 | } |
| 387 | returnCode(result); |
| 388 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 389 | |
| 390 | #if NCURSES_SP_FUNCS |
| 391 | NCURSES_EXPORT(int) |
| 392 | intrflush(WINDOW *win GCC_UNUSED, bool flag) |
| 393 | { |
| 394 | return NCURSES_SP_NAME(intrflush) (CURRENT_SCREEN, win, flag); |
| 395 | } |
| 396 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 397 | |
| 398 | #if NCURSES_EXT_FUNCS |
| 399 | /* *INDENT-OFF* */ |
| 400 | |
| 401 | /* |
| 402 | * SCREEN is always opaque, but nl/raw/cbreak/echo set properties in it. |
| 403 | * As an extension, provide a way to query the properties. |
| 404 | * |
| 405 | * There are other properties which could be queried, e.g., filter, keypad, |
| 406 | * use_env, use_meta, but these particular properties are saved/restored within |
| 407 | * the wgetnstr() and wgetn_wstr() functions, which requires that the higher |
| 408 | * level curses library knows about the internal state of the lower level |
| 409 | * terminfo library. |
| 410 | */ |
| 411 | |
| 412 | #define is_TEST(show,what) \ |
| 413 | NCURSES_EXPORT(int) \ |
| 414 | NCURSES_SP_NAME(show) (NCURSES_SP_DCL0) \ |
| 415 | { \ |
| 416 | return ((SP_PARM != NULL) ? (what(SP_PARM) ? 1 : 0) : -1); \ |
| 417 | } |
| 418 | |
| 419 | is_TEST(is_nl, IsNl) |
| 420 | is_TEST(is_raw, IsRaw) |
| 421 | is_TEST(is_cbreak, IsCbreak) |
| 422 | is_TEST(is_echo, IsEcho) |
| 423 | |
| 424 | #if NCURSES_SP_FUNCS |
| 425 | #undef is_TEST |
| 426 | #define is_TEST(show) \ |
| 427 | NCURSES_EXPORT(int) \ |
| 428 | show(void) \ |
| 429 | { \ |
| 430 | return NCURSES_SP_NAME(show) (CURRENT_SCREEN); \ |
| 431 | } |
| 432 | is_TEST(is_nl) |
| 433 | is_TEST(is_raw) |
| 434 | is_TEST(is_cbreak) |
| 435 | is_TEST(is_echo) |
| 436 | #endif |
| 437 | |
| 438 | /* *INDENT-ON* */ |
| 439 | #endif /* extensions */ |