xref: /openbsd/lib/libcurses/tinfo/lib_ttyflags.c (revision 404b540a)
1 /*	$OpenBSD: lib_ttyflags.c,v 1.4 2001/01/22 18:01:54 millert Exp $	*/
2 
3 /****************************************************************************
4  * Copyright (c) 1998,2000 Free Software Foundation, Inc.                   *
5  *                                                                          *
6  * Permission is hereby granted, free of charge, to any person obtaining a  *
7  * copy of this software and associated documentation files (the            *
8  * "Software"), to deal in the Software without restriction, including      *
9  * without limitation the rights to use, copy, modify, merge, publish,      *
10  * distribute, distribute with modifications, sublicense, and/or sell       *
11  * copies of the Software, and to permit persons to whom the Software is    *
12  * furnished to do so, subject to the following conditions:                 *
13  *                                                                          *
14  * The above copyright notice and this permission notice shall be included  *
15  * in all copies or substantial portions of the Software.                   *
16  *                                                                          *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
18  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
19  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
20  * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
21  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
22  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
23  * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
24  *                                                                          *
25  * Except as contained in this notice, the name(s) of the above copyright   *
26  * holders shall not be used in advertising or otherwise to promote the     *
27  * sale, use or other dealings in this Software without prior written       *
28  * authorization.                                                           *
29  ****************************************************************************/
30 
31 /*
32  *		def_prog_mode()
33  *		def_shell_mode()
34  *		reset_prog_mode()
35  *		reset_shell_mode()
36  *		savetty()
37  *		resetty()
38  */
39 
40 #include <curses.priv.h>
41 #include <term.h>		/* cur_term */
42 
43 MODULE_ID("$From: lib_ttyflags.c,v 1.5 2000/12/10 02:55:08 tom Exp $")
44 
45 #undef tabs
46 
47 #ifdef TAB3
48 # define tabs TAB3
49 #else
50 # ifdef XTABS
51 #  define tabs XTABS
52 # else
53 #  ifdef OXTABS
54 #   define tabs OXTABS
55 #  else
56 #   define tabs 0
57 #  endif
58 # endif
59 #endif
60 
61 NCURSES_EXPORT(int)
62 _nc_get_tty_mode(TTY * buf)
63 {
64     if (cur_term == 0
65 	|| GET_TTY(cur_term->Filedes, buf) != 0)
66 	return (ERR);
67     TR(TRACE_BITS, ("_nc_get_tty_mode: %s", _nc_tracebits()));
68     return (OK);
69 }
70 
71 NCURSES_EXPORT(int)
72 _nc_set_tty_mode(TTY * buf)
73 {
74     if (cur_term == 0
75 	|| SET_TTY(cur_term->Filedes, buf) != 0)
76 	return (ERR);
77     TR(TRACE_BITS, ("_nc_set_tty_mode: %s", _nc_tracebits()));
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 	_nc_set_tty_mode(&cur_term->Nttyb);
125 	if (SP) {
126 	    if (stdscr && stdscr->_use_keypad)
127 		_nc_keypad(TRUE);
128 	    NC_BUFFERED(TRUE);
129 	}
130 	returnCode(OK);
131     }
132     returnCode(ERR);
133 }
134 
135 NCURSES_EXPORT(int)
136 reset_shell_mode(void)
137 {
138     T((T_CALLED("reset_shell_mode()")));
139 
140     if (cur_term != 0) {
141 	if (SP) {
142 	    _nc_keypad(FALSE);
143 	    _nc_flush();
144 	    NC_BUFFERED(FALSE);
145 	}
146 	returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
147     }
148     returnCode(ERR);
149 }
150 
151 /*
152 **	savetty()  and  resetty()
153 **
154 */
155 
156 static TTY buf;
157 
158 NCURSES_EXPORT(int)
159 savetty(void)
160 {
161     T((T_CALLED("savetty()")));
162 
163     returnCode(_nc_get_tty_mode(&buf));
164 }
165 
166 NCURSES_EXPORT(int)
167 resetty(void)
168 {
169     T((T_CALLED("resetty()")));
170 
171     returnCode(_nc_set_tty_mode(&buf));
172 }
173