1 /****************************************************************************
2 * Copyright (c) 1998-2010,2012 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.28 2012/01/21 19:21:29 KO.Myung-Hun Exp $")
47 NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
51 if (buf == 0 || SP_PARM == 0) {
54 TERMINAL *termp = TerminalOf(SP_PARM);
59 #ifdef USE_TERM_DRIVER
60 result = CallDriver_2(SP_PARM, sgmode, FALSE, buf);
63 if (GET_TTY(termp->Filedes, buf) != 0) {
74 memset(buf, 0, sizeof(*buf));
76 TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
77 termp ? termp->Filedes : -1,
78 _nc_trace_ttymode(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, sgmode, TRUE, buf);
108 if ((SET_TTY(termp->Filedes, buf) != 0)
110 && !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)"), (void *) SP_PARM));
147 #ifdef USE_TERM_DRIVER
148 rc = CallDriver_2(SP_PARM, mode, FALSE, TRUE);
151 * If XTABS was on, remove the tab and backtab capabilities.
153 if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
155 if (termp->Ottyb.c_oflag & OFLAGS_TABS)
156 tab = back_tab = NULL;
158 if (termp->Ottyb.sg_flags & XTABS)
159 tab = back_tab = NULL;
172 return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
177 NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
180 TERMINAL *termp = TerminalOf(SP_PARM);
182 T((T_CALLED("def_prog_mode(%p)"), (void *) SP_PARM));
185 #ifdef USE_TERM_DRIVER
186 rc = CallDriver_2(SP_PARM, mode, TRUE, TRUE);
189 * Turn off the XTABS bit in the tty structure if it was on.
191 if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
193 termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
195 termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
208 return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
213 NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
216 TERMINAL *termp = TerminalOf(SP_PARM);
218 T((T_CALLED("reset_prog_mode(%p)"), (void *) SP_PARM));
221 #ifdef USE_TERM_DRIVER
222 rc = CallDriver_2(SP_PARM, mode, TRUE, FALSE);
224 if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
226 if (SP_PARM->_keypad_on)
227 _nc_keypad(SP_PARM, TRUE);
228 NC_BUFFERED(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)"), (void *) SP_PARM));
254 #ifdef USE_TERM_DRIVER
255 rc = CallDriver_2(SP_PARM, mode, FALSE, FALSE);
258 _nc_keypad(SP_PARM, FALSE);
260 NC_BUFFERED(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);