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 ****************************************************************************/
39 #include <curses.priv.h>
42 #define CUR SP_TERMTYPE
45 MODULE_ID("$Id: lib_ttyflags.c,v 1.36 2020/09/05 22:54:47 tom Exp $")
48 NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
50 TERMINAL *termp = TerminalOf(SP_PARM);
53 if (buf == 0 || termp == 0) {
57 #ifdef USE_TERM_DRIVER
59 result = CallDriver_2(SP_PARM, td_sgmode, FALSE, buf);
65 if (GET_TTY(termp->Filedes, buf) != 0) {
74 TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
75 termp ? termp->Filedes : -1,
76 _nc_trace_ttymode(buf)));
78 if (result == ERR && buf != 0)
79 memset(buf, 0, sizeof(*buf));
86 _nc_get_tty_mode(TTY * buf)
88 return NCURSES_SP_NAME(_nc_get_tty_mode) (CURRENT_SCREEN, buf);
93 NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_DCLx TTY * buf)
97 if (buf == 0 || SP_PARM == 0) {
100 TERMINAL *termp = TerminalOf(SP_PARM);
105 #ifdef USE_TERM_DRIVER
106 result = CallDriver_2(SP_PARM, td_sgmode, TRUE, buf);
109 if ((SET_TTY(termp->Filedes, buf) != 0)
111 && !NC_ISATTY(termp->Filedes)
116 if ((errno == ENOTTY) && (SP_PARM != 0))
117 SP_PARM->_notty = TRUE;
124 TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
125 termp ? termp->Filedes : -1,
126 _nc_trace_ttymode(buf)));
133 _nc_set_tty_mode(TTY * buf)
135 return NCURSES_SP_NAME(_nc_set_tty_mode) (CURRENT_SCREEN, buf);
140 NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
143 TERMINAL *termp = TerminalOf(SP_PARM);
145 T((T_CALLED("def_shell_mode(%p) ->term %p"),
146 (void *) SP_PARM, (void *) termp));
149 #ifdef USE_TERM_DRIVER
150 rc = CallDriver_2(SP_PARM, td_mode, FALSE, TRUE);
153 * If XTABS was on, remove the tab and backtab capabilities.
155 if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
157 if (termp->Ottyb.c_oflag & OFLAGS_TABS)
158 tab = back_tab = NULL;
159 #elif defined(EXP_WIN32_DRIVER)
162 if (termp->Ottyb.sg_flags & XTABS)
163 tab = back_tab = NULL;
176 return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
181 NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
184 TERMINAL *termp = TerminalOf(SP_PARM);
186 T((T_CALLED("def_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp));
189 #ifdef USE_TERM_DRIVER
190 rc = CallDriver_2(SP_PARM, td_mode, TRUE, TRUE);
193 * Turn off the XTABS bit in the tty structure if it was on.
195 if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
197 termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
198 #elif defined(EXP_WIN32_DRIVER)
201 termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
214 return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
219 NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
222 TERMINAL *termp = TerminalOf(SP_PARM);
224 T((T_CALLED("reset_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp));
227 #ifdef USE_TERM_DRIVER
228 rc = CallDriver_2(SP_PARM, td_mode, TRUE, FALSE);
230 if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
232 if (SP_PARM->_keypad_on)
233 _nc_keypad(SP_PARM, TRUE);
244 reset_prog_mode(void)
246 return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN);
251 NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
254 TERMINAL *termp = TerminalOf(SP_PARM);
256 T((T_CALLED("reset_shell_mode(%p) ->term %p"),
257 (void *) SP_PARM, (void *) termp));
260 #ifdef USE_TERM_DRIVER
261 rc = CallDriver_2(SP_PARM, td_mode, FALSE, FALSE);
264 _nc_keypad(SP_PARM, FALSE);
267 rc = _nc_set_tty_mode(&termp->Ottyb);
275 reset_shell_mode(void)
277 return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN);
282 saved_tty(NCURSES_SP_DCL0)
287 result = (TTY *) & (SP_PARM->_saved_tty);
289 if (_nc_prescreen.saved_tty == 0) {
290 _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
292 result = _nc_prescreen.saved_tty;
298 ** savetty() and resetty()
303 NCURSES_SP_NAME(savetty) (NCURSES_SP_DCL0)
305 T((T_CALLED("savetty(%p)"), (void *) SP_PARM));
306 returnCode(NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
313 return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN);
318 NCURSES_SP_NAME(resetty) (NCURSES_SP_DCL0)
320 T((T_CALLED("resetty(%p)"), (void *) SP_PARM));
321 returnCode(NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
328 return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN);