1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 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.27 2010/12/25 23:43:58 tom 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) {
111 if ((errno
== ENOTTY
) && (SP_PARM
!= 0))
112 SP_PARM
->_notty
= TRUE
;
119 TR(TRACE_BITS
, ("_nc_set_tty_mode(%d): %s",
120 termp
? termp
->Filedes
: -1,
121 _nc_trace_ttymode(buf
)));
128 _nc_set_tty_mode(TTY
* buf
)
130 return NCURSES_SP_NAME(_nc_set_tty_mode
) (CURRENT_SCREEN
, buf
);
135 NCURSES_SP_NAME(def_shell_mode
) (NCURSES_SP_DCL0
)
138 TERMINAL
*termp
= TerminalOf(SP_PARM
);
140 T((T_CALLED("def_shell_mode(%p)"), (void *) SP_PARM
));
143 #ifdef USE_TERM_DRIVER
144 rc
= CallDriver_2(SP_PARM
, mode
, FALSE
, TRUE
);
147 * If XTABS was on, remove the tab and backtab capabilities.
149 if (_nc_get_tty_mode(&termp
->Ottyb
) == OK
) {
151 if (termp
->Ottyb
.c_oflag
& OFLAGS_TABS
)
152 tab
= back_tab
= NULL
;
154 if (termp
->Ottyb
.sg_flags
& XTABS
)
155 tab
= back_tab
= NULL
;
168 return NCURSES_SP_NAME(def_shell_mode
) (CURRENT_SCREEN
);
173 NCURSES_SP_NAME(def_prog_mode
) (NCURSES_SP_DCL0
)
176 TERMINAL
*termp
= TerminalOf(SP_PARM
);
178 T((T_CALLED("def_prog_mode(%p)"), (void *) SP_PARM
));
181 #ifdef USE_TERM_DRIVER
182 rc
= CallDriver_2(SP_PARM
, mode
, TRUE
, TRUE
);
185 * Turn off the XTABS bit in the tty structure if it was on.
187 if (_nc_get_tty_mode(&termp
->Nttyb
) == OK
) {
189 termp
->Nttyb
.c_oflag
&= (unsigned) (~OFLAGS_TABS
);
191 termp
->Nttyb
.sg_flags
&= (unsigned) (~XTABS
);
204 return NCURSES_SP_NAME(def_prog_mode
) (CURRENT_SCREEN
);
209 NCURSES_SP_NAME(reset_prog_mode
) (NCURSES_SP_DCL0
)
212 TERMINAL
*termp
= TerminalOf(SP_PARM
);
214 T((T_CALLED("reset_prog_mode(%p)"), (void *) SP_PARM
));
217 #ifdef USE_TERM_DRIVER
218 rc
= CallDriver_2(SP_PARM
, mode
, TRUE
, FALSE
);
220 if (_nc_set_tty_mode(&termp
->Nttyb
) == OK
) {
222 if (SP_PARM
->_keypad_on
)
223 _nc_keypad(SP_PARM
, TRUE
);
224 NC_BUFFERED(SP_PARM
, TRUE
);
235 reset_prog_mode(void)
237 return NCURSES_SP_NAME(reset_prog_mode
) (CURRENT_SCREEN
);
242 NCURSES_SP_NAME(reset_shell_mode
) (NCURSES_SP_DCL0
)
245 TERMINAL
*termp
= TerminalOf(SP_PARM
);
247 T((T_CALLED("reset_shell_mode(%p)"), (void *) SP_PARM
));
250 #ifdef USE_TERM_DRIVER
251 rc
= CallDriver_2(SP_PARM
, mode
, FALSE
, FALSE
);
254 _nc_keypad(SP_PARM
, FALSE
);
256 NC_BUFFERED(SP_PARM
, FALSE
);
258 rc
= _nc_set_tty_mode(&termp
->Ottyb
);
266 reset_shell_mode(void)
268 return NCURSES_SP_NAME(reset_shell_mode
) (CURRENT_SCREEN
);
273 saved_tty(NCURSES_SP_DCL0
)
278 result
= (TTY
*) & (SP_PARM
->_saved_tty
);
280 if (_nc_prescreen
.saved_tty
== 0) {
281 _nc_prescreen
.saved_tty
= typeCalloc(TTY
, 1);
283 result
= _nc_prescreen
.saved_tty
;
289 ** savetty() and resetty()
294 NCURSES_SP_NAME(savetty
) (NCURSES_SP_DCL0
)
296 T((T_CALLED("savetty(%p)"), (void *) SP_PARM
));
297 returnCode(NCURSES_SP_NAME(_nc_get_tty_mode
) (NCURSES_SP_ARGx
saved_tty(NCURSES_SP_ARG
)));
304 return NCURSES_SP_NAME(savetty
) (CURRENT_SCREEN
);
309 NCURSES_SP_NAME(resetty
) (NCURSES_SP_DCL0
)
311 T((T_CALLED("resetty(%p)"), (void *) SP_PARM
));
312 returnCode(NCURSES_SP_NAME(_nc_set_tty_mode
) (NCURSES_SP_ARGx
saved_tty(NCURSES_SP_ARG
)));
319 return NCURSES_SP_NAME(resetty
) (CURRENT_SCREEN
);