1 /****************************************************************************
2 * Copyright (c) 1998-2016,2017 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 ****************************************************************************/
38 #include <curses.priv.h>
41 #define CUR SP_TERMTYPE
44 MODULE_ID("$Id: lib_ttyflags.c,v 1.33 2017/04/02 14:30:26 tom Exp $")
47 NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
49 TERMINAL *termp = TerminalOf(SP_PARM);
52 if (buf == 0 || termp == 0) {
56 #ifdef USE_TERM_DRIVER
58 result = CallDriver_2(SP_PARM, td_sgmode, FALSE, buf);
64 if (GET_TTY(termp->Filedes, buf) != 0) {
73 TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
74 termp ? termp->Filedes : -1,
75 _nc_trace_ttymode(buf)));
77 if (result == ERR && buf != 0)
78 memset(buf, 0, sizeof(*buf));
85 _nc_get_tty_mode(TTY * buf)
87 return NCURSES_SP_NAME(_nc_get_tty_mode) (CURRENT_SCREEN, buf);
92 NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_DCLx TTY * buf)
96 if (buf == 0 || SP_PARM == 0) {
99 TERMINAL *termp = TerminalOf(SP_PARM);
104 #ifdef USE_TERM_DRIVER
105 result = CallDriver_2(SP_PARM, td_sgmode, TRUE, buf);
108 if ((SET_TTY(termp->Filedes, buf) != 0)
110 && !NC_ISATTY(termp->Filedes)
115 if ((errno == ENOTTY) && (SP_PARM != 0))
116 SP_PARM->_notty = TRUE;
123 TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
124 termp ? termp->Filedes : -1,
125 _nc_trace_ttymode(buf)));
132 _nc_set_tty_mode(TTY * buf)
134 return NCURSES_SP_NAME(_nc_set_tty_mode) (CURRENT_SCREEN, buf);
139 NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
142 TERMINAL *termp = TerminalOf(SP_PARM);
144 T((T_CALLED("def_shell_mode(%p) ->term %p"),
145 (void *) SP_PARM, (void *) termp));
148 #ifdef USE_TERM_DRIVER
149 rc = CallDriver_2(SP_PARM, td_mode, FALSE, TRUE);
152 * If XTABS was on, remove the tab and backtab capabilities.
154 if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
156 if (termp->Ottyb.c_oflag & OFLAGS_TABS)
157 tab = back_tab = NULL;
159 if (termp->Ottyb.sg_flags & XTABS)
160 tab = back_tab = NULL;
173 return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
178 NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
181 TERMINAL *termp = TerminalOf(SP_PARM);
183 T((T_CALLED("def_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp));
186 #ifdef USE_TERM_DRIVER
187 rc = CallDriver_2(SP_PARM, td_mode, TRUE, TRUE);
190 * Turn off the XTABS bit in the tty structure if it was on.
192 if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
194 termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
196 termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
209 return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
214 NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
217 TERMINAL *termp = TerminalOf(SP_PARM);
219 T((T_CALLED("reset_prog_mode(%p) ->term %p"), (void *) SP_PARM, (void *) termp));
222 #ifdef USE_TERM_DRIVER
223 rc = CallDriver_2(SP_PARM, td_mode, TRUE, FALSE);
225 if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
227 if (SP_PARM->_keypad_on)
228 _nc_keypad(SP_PARM, TRUE);
239 reset_prog_mode(void)
241 return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN);
246 NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
249 TERMINAL *termp = TerminalOf(SP_PARM);
251 T((T_CALLED("reset_shell_mode(%p) ->term %p"),
252 (void *) SP_PARM, (void *) termp));
255 #ifdef USE_TERM_DRIVER
256 rc = CallDriver_2(SP_PARM, td_mode, FALSE, FALSE);
259 _nc_keypad(SP_PARM, FALSE);
262 rc = _nc_set_tty_mode(&termp->Ottyb);
270 reset_shell_mode(void)
272 return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN);
277 saved_tty(NCURSES_SP_DCL0)
282 result = (TTY *) & (SP_PARM->_saved_tty);
284 if (_nc_prescreen.saved_tty == 0) {
285 _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
287 result = _nc_prescreen.saved_tty;
293 ** savetty() and resetty()
298 NCURSES_SP_NAME(savetty) (NCURSES_SP_DCL0)
300 T((T_CALLED("savetty(%p)"), (void *) SP_PARM));
301 returnCode(NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
308 return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN);
313 NCURSES_SP_NAME(resetty) (NCURSES_SP_DCL0)
315 T((T_CALLED("resetty(%p)"), (void *) SP_PARM));
316 returnCode(NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx saved_tty(NCURSES_SP_ARG)));
323 return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN);