missing ncurses sources
[tomato.git] / release / src / router / libncurses / ncurses / tinfo / lib_ttyflags.c
blob663a0689809001ae35372d453d0afd04650faa2d
1 /****************************************************************************
2 * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc. *
3 * *
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: *
11 * *
12 * The above copyright notice and this permission notice shall be included *
13 * in all copies or substantial portions of the Software. *
14 * *
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. *
22 * *
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 *
26 * authorization. *
27 ****************************************************************************/
30 * def_prog_mode()
31 * def_shell_mode()
32 * reset_prog_mode()
33 * reset_shell_mode()
34 * savetty()
35 * resetty()
38 #include <curses.priv.h>
40 #ifndef CUR
41 #define CUR SP_TERMTYPE
42 #endif
44 MODULE_ID("$Id: lib_ttyflags.c,v 1.27 2010/12/25 23:43:58 tom Exp $")
46 NCURSES_EXPORT(int)
47 NCURSES_SP_NAME(_nc_get_tty_mode) (NCURSES_SP_DCLx TTY * buf)
49 int result = OK;
51 if (buf == 0 || SP_PARM == 0) {
52 result = ERR;
53 } else {
54 TERMINAL *termp = TerminalOf(SP_PARM);
56 if (0 == termp) {
57 result = ERR;
58 } else {
59 #ifdef USE_TERM_DRIVER
60 result = CallDriver_2(SP_PARM, sgmode, FALSE, buf);
61 #else
62 for (;;) {
63 if (GET_TTY(termp->Filedes, buf) != 0) {
64 if (errno == EINTR)
65 continue;
66 result = ERR;
68 break;
70 #endif
73 if (result == ERR)
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)));
80 return (result);
83 #if NCURSES_SP_FUNCS
84 NCURSES_EXPORT(int)
85 _nc_get_tty_mode(TTY * buf)
87 return NCURSES_SP_NAME(_nc_get_tty_mode) (CURRENT_SCREEN, buf);
89 #endif
91 NCURSES_EXPORT(int)
92 NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_DCLx TTY * buf)
94 int result = OK;
96 if (buf == 0 || SP_PARM == 0) {
97 result = ERR;
98 } else {
99 TERMINAL *termp = TerminalOf(SP_PARM);
101 if (0 == termp) {
102 result = ERR;
103 } else {
104 #ifdef USE_TERM_DRIVER
105 result = CallDriver_2(SP_PARM, sgmode, TRUE, buf);
106 #else
107 for (;;) {
108 if (SET_TTY(termp->Filedes, buf) != 0) {
109 if (errno == EINTR)
110 continue;
111 if ((errno == ENOTTY) && (SP_PARM != 0))
112 SP_PARM->_notty = TRUE;
113 result = ERR;
115 break;
117 #endif
119 TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
120 termp ? termp->Filedes : -1,
121 _nc_trace_ttymode(buf)));
123 return (result);
126 #if NCURSES_SP_FUNCS
127 NCURSES_EXPORT(int)
128 _nc_set_tty_mode(TTY * buf)
130 return NCURSES_SP_NAME(_nc_set_tty_mode) (CURRENT_SCREEN, buf);
132 #endif
134 NCURSES_EXPORT(int)
135 NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_DCL0)
137 int rc = ERR;
138 TERMINAL *termp = TerminalOf(SP_PARM);
140 T((T_CALLED("def_shell_mode(%p)"), (void *) SP_PARM));
142 if (termp != 0) {
143 #ifdef USE_TERM_DRIVER
144 rc = CallDriver_2(SP_PARM, mode, FALSE, TRUE);
145 #else
147 * If XTABS was on, remove the tab and backtab capabilities.
149 if (_nc_get_tty_mode(&termp->Ottyb) == OK) {
150 #ifdef TERMIOS
151 if (termp->Ottyb.c_oflag & OFLAGS_TABS)
152 tab = back_tab = NULL;
153 #else
154 if (termp->Ottyb.sg_flags & XTABS)
155 tab = back_tab = NULL;
156 #endif
157 rc = OK;
159 #endif
161 returnCode(rc);
164 #if NCURSES_SP_FUNCS
165 NCURSES_EXPORT(int)
166 def_shell_mode(void)
168 return NCURSES_SP_NAME(def_shell_mode) (CURRENT_SCREEN);
170 #endif
172 NCURSES_EXPORT(int)
173 NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_DCL0)
175 int rc = ERR;
176 TERMINAL *termp = TerminalOf(SP_PARM);
178 T((T_CALLED("def_prog_mode(%p)"), (void *) SP_PARM));
180 if (termp != 0) {
181 #ifdef USE_TERM_DRIVER
182 rc = CallDriver_2(SP_PARM, mode, TRUE, TRUE);
183 #else
185 * Turn off the XTABS bit in the tty structure if it was on.
187 if (_nc_get_tty_mode(&termp->Nttyb) == OK) {
188 #ifdef TERMIOS
189 termp->Nttyb.c_oflag &= (unsigned) (~OFLAGS_TABS);
190 #else
191 termp->Nttyb.sg_flags &= (unsigned) (~XTABS);
192 #endif
193 rc = OK;
195 #endif
197 returnCode(rc);
200 #if NCURSES_SP_FUNCS
201 NCURSES_EXPORT(int)
202 def_prog_mode(void)
204 return NCURSES_SP_NAME(def_prog_mode) (CURRENT_SCREEN);
206 #endif
208 NCURSES_EXPORT(int)
209 NCURSES_SP_NAME(reset_prog_mode) (NCURSES_SP_DCL0)
211 int rc = ERR;
212 TERMINAL *termp = TerminalOf(SP_PARM);
214 T((T_CALLED("reset_prog_mode(%p)"), (void *) SP_PARM));
216 if (termp != 0) {
217 #ifdef USE_TERM_DRIVER
218 rc = CallDriver_2(SP_PARM, mode, TRUE, FALSE);
219 #else
220 if (_nc_set_tty_mode(&termp->Nttyb) == OK) {
221 if (SP_PARM) {
222 if (SP_PARM->_keypad_on)
223 _nc_keypad(SP_PARM, TRUE);
224 NC_BUFFERED(SP_PARM, TRUE);
226 rc = OK;
228 #endif
230 returnCode(rc);
233 #if NCURSES_SP_FUNCS
234 NCURSES_EXPORT(int)
235 reset_prog_mode(void)
237 return NCURSES_SP_NAME(reset_prog_mode) (CURRENT_SCREEN);
239 #endif
241 NCURSES_EXPORT(int)
242 NCURSES_SP_NAME(reset_shell_mode) (NCURSES_SP_DCL0)
244 int rc = ERR;
245 TERMINAL *termp = TerminalOf(SP_PARM);
247 T((T_CALLED("reset_shell_mode(%p)"), (void *) SP_PARM));
249 if (termp != 0) {
250 #ifdef USE_TERM_DRIVER
251 rc = CallDriver_2(SP_PARM, mode, FALSE, FALSE);
252 #else
253 if (SP_PARM) {
254 _nc_keypad(SP_PARM, FALSE);
255 _nc_flush();
256 NC_BUFFERED(SP_PARM, FALSE);
258 rc = _nc_set_tty_mode(&termp->Ottyb);
259 #endif
261 returnCode(rc);
264 #if NCURSES_SP_FUNCS
265 NCURSES_EXPORT(int)
266 reset_shell_mode(void)
268 return NCURSES_SP_NAME(reset_shell_mode) (CURRENT_SCREEN);
270 #endif
272 static TTY *
273 saved_tty(NCURSES_SP_DCL0)
275 TTY *result = 0;
277 if (SP_PARM != 0) {
278 result = (TTY *) & (SP_PARM->_saved_tty);
279 } else {
280 if (_nc_prescreen.saved_tty == 0) {
281 _nc_prescreen.saved_tty = typeCalloc(TTY, 1);
283 result = _nc_prescreen.saved_tty;
285 return result;
289 ** savetty() and resetty()
293 NCURSES_EXPORT(int)
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)));
300 #if NCURSES_SP_FUNCS
301 NCURSES_EXPORT(int)
302 savetty(void)
304 return NCURSES_SP_NAME(savetty) (CURRENT_SCREEN);
306 #endif
308 NCURSES_EXPORT(int)
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)));
315 #if NCURSES_SP_FUNCS
316 NCURSES_EXPORT(int)
317 resetty(void)
319 return NCURSES_SP_NAME(resetty) (CURRENT_SCREEN);
321 #endif