]> ncurses.scripts.mit.edu Git - ncurses.git/blob - ncurses/tinfo/lib_raw.c
ncurses 5.0
[ncurses.git] / ncurses / tinfo / lib_raw.c
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  *  Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995               *
31  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
32  ****************************************************************************/
33
34
35 /*
36  *      raw.c
37  *
38  *      Routines:
39  *              raw()
40  *              cbreak()
41  *              noraw()
42  *              nocbreak()
43  *              qiflush()
44  *              noqiflush()
45  *              intrflush()
46  *
47  */
48
49 #include <curses.priv.h>
50 #include <term.h>       /* cur_term */
51
52 MODULE_ID("$Id: lib_raw.c,v 1.3 1999/03/06 22:28:24 tom Exp $")
53
54 #if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE)
55 #define _POSIX_SOURCE
56 #endif
57
58 #if HAVE_SYS_TERMIO_H
59 #include <sys/termio.h> /* needed for ISC */
60 #endif
61
62 #ifdef __EMX__
63 #include <io.h>
64 #include <fcntl.h>
65 #endif
66
67 #define COOKED_INPUT    (IXON|BRKINT|PARMRK)
68
69 #ifdef TRACE
70 #define BEFORE(N)       if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits())
71 #define AFTER(N)        if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits())
72 #else
73 #define BEFORE(s)
74 #define AFTER(s)
75 #endif /* TRACE */
76
77 int raw(void)
78 {
79         T((T_CALLED("raw()")));
80         if (SP != 0 && cur_term != 0) {
81
82                 SP->_raw = TRUE;
83                 SP->_cbreak = 1;
84
85 #ifdef __EMX__
86                 setmode(SP->_ifd, O_BINARY);
87 #endif
88
89 #ifdef TERMIOS
90                 BEFORE("raw");
91                 cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG);
92                 cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
93                 cur_term->Nttyb.c_cc[VMIN] = 1;
94                 cur_term->Nttyb.c_cc[VTIME] = 0;
95                 AFTER("raw");
96 #else
97                 cur_term->Nttyb.sg_flags |= RAW;
98 #endif
99                 returnCode(_nc_set_tty_mode(&cur_term->Nttyb));
100         }
101         returnCode(ERR);
102 }
103
104 int cbreak(void)
105 {
106         T((T_CALLED("cbreak()")));
107
108         SP->_cbreak = 1;
109
110 #ifdef __EMX__
111         setmode(SP->_ifd, O_BINARY);
112 #endif
113
114 #ifdef TERMIOS
115         BEFORE("cbreak");
116         cur_term->Nttyb.c_lflag &= ~ICANON;
117         cur_term->Nttyb.c_iflag &= ~ICRNL;
118         cur_term->Nttyb.c_lflag |= ISIG;
119         cur_term->Nttyb.c_cc[VMIN] = 1;
120         cur_term->Nttyb.c_cc[VTIME] = 0;
121         AFTER("cbreak");
122 #else
123         cur_term->Nttyb.sg_flags |= CBREAK;
124 #endif
125         returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
126 }
127
128 void qiflush(void)
129 {
130         T((T_CALLED("qiflush()")));
131
132         /*
133          * Note: this implementation may be wrong.  See the comment under
134          * intrflush().
135          */
136
137 #ifdef TERMIOS
138         BEFORE("qiflush");
139         cur_term->Nttyb.c_lflag &= ~(NOFLSH);
140         AFTER("qiflush");
141         (void)_nc_set_tty_mode( &cur_term->Nttyb);
142         returnVoid;
143 #endif
144 }
145
146
147 int noraw(void)
148 {
149         T((T_CALLED("noraw()")));
150
151         SP->_raw = FALSE;
152         SP->_cbreak = 0;
153
154 #ifdef __EMX__
155         setmode(SP->_ifd, O_TEXT);
156 #endif
157
158 #ifdef TERMIOS
159         BEFORE("noraw");
160         cur_term->Nttyb.c_lflag |= ISIG|ICANON;
161         cur_term->Nttyb.c_iflag |= COOKED_INPUT;
162         AFTER("noraw");
163 #else
164         cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
165 #endif
166         returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
167 }
168
169
170 int nocbreak(void)
171 {
172         T((T_CALLED("nocbreak()")));
173
174         SP->_cbreak = 0;
175
176 #ifdef __EMX__
177         setmode(SP->_ifd, O_TEXT);
178 #endif
179
180 #ifdef TERMIOS
181         BEFORE("nocbreak");
182         cur_term->Nttyb.c_lflag |= ICANON;
183         cur_term->Nttyb.c_iflag |= ICRNL;
184         AFTER("nocbreak");
185 #else
186         cur_term->Nttyb.sg_flags &= ~CBREAK;
187 #endif
188         returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
189 }
190
191 void noqiflush(void)
192 {
193         T((T_CALLED("noqiflush()")));
194
195         /*
196          * Note: this implementation may be wrong.  See the comment under
197          * intrflush().
198          */
199
200 #ifdef TERMIOS
201         BEFORE("noqiflush");
202         cur_term->Nttyb.c_lflag |= NOFLSH;
203         AFTER("noqiflush");
204         (void)_nc_set_tty_mode( &cur_term->Nttyb);
205         returnVoid;
206 #endif
207 }
208
209 int intrflush(WINDOW *win GCC_UNUSED, bool flag)
210 {
211         T((T_CALLED("intrflush(%d)"), flag));
212
213         /*
214          * This call does the same thing as the qiflush()/noqiflush()
215          * pair.  We know for certain that SVr3 intrflush() tweaks the
216          * NOFLSH bit; on the other hand, the match (in the SVr4 man
217          * pages) between the language describing NOFLSH in termio(7)
218          * and the language describing qiflush()/noqiflush() in
219          * curs_inopts(3x) is too exact to be coincidence.
220          */
221
222 #ifdef TERMIOS
223         BEFORE("intrflush");
224         if (flag)
225                 cur_term->Nttyb.c_lflag &= ~(NOFLSH);
226         else
227                 cur_term->Nttyb.c_lflag |= (NOFLSH);
228         AFTER("intrflush");
229         returnCode(_nc_set_tty_mode( &cur_term->Nttyb));
230 #else
231         returnCode(ERR);
232 #endif
233 }