lib_ttyflags.c revision 56639
1/****************************************************************************
2 * Copyright (c) 1998 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
41MODULE_ID("$Id: lib_ttyflags.c,v 1.3 1999/10/22 21:38:55 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
59int _nc_get_tty_mode(TTY *buf)
60{
61	if (cur_term == 0
62	 || GET_TTY(cur_term->Filedes, buf) != 0)
63		return(ERR);
64	TR(TRACE_BITS,("_nc_get_tty_mode: %s", _nc_tracebits()));
65	return (OK);
66}
67
68int _nc_set_tty_mode(TTY *buf)
69{
70	if (cur_term == 0
71	 || SET_TTY(cur_term->Filedes, buf) != 0)
72		return(ERR);
73	TR(TRACE_BITS,("_nc_set_tty_mode: %s", _nc_tracebits()));
74	return (OK);
75}
76
77int def_shell_mode(void)
78{
79	T((T_CALLED("def_shell_mode()")));
80
81	/*
82	 * Turn off the XTABS bit in the tty structure if it was on.  If XTABS
83	 * was on, remove the tab and backtab capabilities.
84	 */
85
86	if (_nc_get_tty_mode(&cur_term->Ottyb) != OK)
87		returnCode(ERR);
88#ifdef TERMIOS
89	if (cur_term->Ottyb.c_oflag & tabs)
90		tab = back_tab = NULL;
91#else
92	if (cur_term->Ottyb.sg_flags & XTABS)
93		tab = back_tab = NULL;
94#endif
95	returnCode(OK);
96}
97
98int def_prog_mode(void)
99{
100	T((T_CALLED("def_prog_mode()")));
101
102	if (_nc_get_tty_mode(&cur_term->Nttyb) != OK)
103		returnCode(ERR);
104#ifdef TERMIOS
105	cur_term->Nttyb.c_oflag &= ~tabs;
106#else
107	cur_term->Nttyb.sg_flags &= ~XTABS;
108#endif
109	returnCode(OK);
110}
111
112int reset_prog_mode(void)
113{
114	T((T_CALLED("reset_prog_mode()")));
115
116	if (cur_term != 0) {
117		_nc_set_tty_mode(&cur_term->Nttyb);
118		if (SP) {
119			if (stdscr && stdscr->_use_keypad)
120				_nc_keypad(TRUE);
121			NC_BUFFERED(TRUE);
122		}
123		returnCode(OK);
124	}
125	returnCode(ERR);
126}
127
128int reset_shell_mode(void)
129{
130	T((T_CALLED("reset_shell_mode()")));
131
132	if (cur_term != 0) {
133		if (SP)
134		{
135			_nc_keypad(FALSE);
136			_nc_flush();
137			NC_BUFFERED(FALSE);
138		}
139		returnCode(_nc_set_tty_mode(&cur_term->Ottyb));
140	}
141	returnCode(ERR);
142}
143
144/*
145**	savetty()  and  resetty()
146**
147*/
148
149static TTY   buf;
150
151int savetty(void)
152{
153	T((T_CALLED("savetty()")));
154
155	returnCode(_nc_get_tty_mode(&buf));
156}
157
158int resetty(void)
159{
160	T((T_CALLED("resetty()")));
161
162	returnCode(_nc_set_tty_mode(&buf));
163}
164