]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_ttyflags.c
ncurses 5.3
[ncurses.git] / ncurses / tinfo / lib_ttyflags.c
1 /****************************************************************************
2  * Copyright (c) 1998-2001,2002 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  ****************************************************************************/
28
29 /*
30  *              def_prog_mode()
31  *              def_shell_mode()
32  *              reset_prog_mode()
33  *              reset_shell_mode()
34  *              savetty()
35  *              resetty()
36  */
37
38 #include <curses.priv.h>
39 #include <term.h>               /* cur_term */
40
41 MODULE_ID("$Id: lib_ttyflags.c,v 1.9 2002/10/12 21:28:16 tom Exp $")
42
43 #undef tabs
44
45 #ifdef TAB3
46 # define tabs TAB3
47 #else
48 # ifdef XTABS
49 #  define tabs XTABS
50 # else
51 #  ifdef OXTABS
52 #   define tabs OXTABS
53 #  else
54 #   define tabs 0
55 #  endif
56 # endif
57 #endif
58
59 NCURSES_EXPORT(int)
60 _nc_get_tty_mode(TTY * buf)
61 {
62     if (cur_term == 0
63         || GET_TTY(cur_term->Filedes, buf) != 0)
64         return (ERR);
65     TR(TRACE_BITS, ("_nc_get_tty_mode(%d): %s",
66                     cur_term->Filedes, _nc_trace_ttymode(buf)));
67     return (OK);
68 }
69
70 NCURSES_EXPORT(int)
71 _nc_set_tty_mode(TTY * buf)
72 {
73     if (cur_term == 0
74         || SET_TTY(cur_term->Filedes, buf) != 0)
75         return (ERR);
76     TR(TRACE_BITS, ("_nc_set_tty_mode(%d): %s",
77                     cur_term->Filedes, _nc_trace_ttymode(buf)));
78     return (OK);
79 }
80
81 NCURSES_EXPORT(int)
82 def_shell_mode(void)
83 {
84     T((T_CALLED("def_shell_mode()")));
85
86     /*
87      * Turn off the XTABS bit in the tty structure if it was on.  If XTABS
88      * was on, remove the tab and backtab capabilities.
89      */
90
91     if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
92         returnCode(ERR);
93 #ifdef TERMIOS
94     if (cur_term->Ottyb.c_oflag & tabs)
95         tab = back_tab = NULL;
96 #else
97     if (cur_term->Ottyb.sg_flags & XTABS)
98         tab = back_tab = NULL;
99 #endif
100     returnCode(OK);
101 }
102
103 NCURSES_EXPORT(int)
104 def_prog_mode(void)
105 {
106     T((T_CALLED("def_prog_mode()")));
107
108     if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
109         returnCode(ERR);
110 #ifdef TERMIOS
111     cur_term->Nttyb.c_oflag &= ~tabs;
112 #else
113     cur_term->Nttyb.sg_flags &= ~XTABS;
114 #endif
115     returnCode(OK);
116 }
117
118 NCURSES_EXPORT(int)
119 reset_prog_mode(void)
120 {
121     T((T_CALLED("reset_prog_mode()")));
122
123     if (cur_term != 0) {
124         if (_nc_set_tty_mode(&cur_term->Nttyb) == OK) {
125             if (SP) {
126                 if (SP->_keypad_on)
127                     _nc_keypad(TRUE);
128                 NC_BUFFERED(TRUE);
129             }
130             returnCode(OK);
131         }
132     }
133     returnCode(ERR);
134 }
135
136 NCURSES_EXPORT(int)
137 reset_shell_mode(void)
138 {
139     T((T_CALLED("reset_shell_mode()")));
140
141     if (cur_term != 0) {
142         if (SP) {
143             _nc_keypad(FALSE);
144             _nc_flush();
145             NC_BUFFERED(FALSE);
146         }
147         returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
148     }
149     returnCode(ERR);
150 }
151
152 /*
153 **      savetty()  and  resetty()
154 **
155 */
156
157 static TTY buf;
158
159 NCURSES_EXPORT(int)
160 savetty(void)
161 {
162     T((T_CALLED("savetty()")));
163
164     returnCode(_nc_get_tty_mode(&buf));
165 }
166
167 NCURSES_EXPORT(int)
168 resetty(void)
169 {
170     T((T_CALLED("resetty()")));
171
172     returnCode(_nc_set_tty_mode(&buf));
173 }