1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
|
/***************************************************************************
* COPYRIGHT NOTICE *
****************************************************************************
* ncurses is copyright (C) 1992-1995 *
* Zeyd M. Ben-Halim *
* zmbenhal@netcom.com *
* Eric S. Raymond *
* esr@snark.thyrsus.com *
* *
* Permission is hereby granted to reproduce and distribute ncurses *
* by any means and for any fee, whether alone or as part of a *
* larger distribution, in source or in binary form, PROVIDED *
* this notice is included with any such distribution, and is not *
* removed from any of its header files. Mention of ncurses in any *
* applications linked with it is highly appreciated. *
* *
* ncurses comes AS IS with no warranty, implied or expressed. *
* *
***************************************************************************/
/*
* raw.c
*
* Routines:
* raw()
* echo()
* nl()
* cbreak()
* noraw()
* noecho()
* nonl()
* nocbreak()
* qiflush()
* noqiflush()
* intrflush()
*
*/
#include "curses.priv.h"
#include "term.h" /* cur_term */
/*
* COOKED_INPUT defines the collection of input mode bits to be
* cleared when entering raw mode, then re-set by noraw().
*
* We used to clear ISTRIP and INPCK when going to raw mode. Keith
* Bostic says that's wrong, because those are hardware bits that the
* user has to get right in his/her initial environment -- he says
* curses can't do any good by clearing these, and may do harm. In
* 1995's world of 8N1 connections over error-correcting modems, all
* the parity-check stuff is pretty nearly irrelevant anyway.
*
* What's supposed to happen when noraw() executes has never been very
* well-defined. Yes, it should reset ISIG/ICANON/OPOST (historical
* practice is for it to attempt to take the driver back to cooked
* mode, rather going to some half-baked cbreak-like intermediate
* level).
*
* We make a design choice here to turn off CR/LF translation a la BSD
* when raw() is enabled, on the theory that a programmer requesting
* raw() ideally wants an 8-bit data stream that's been messed with as
* little as possible. The man pages document this.
*
* We originally opted for the simplest way to handle noraw(); just set all
* the flags we cleared. Unfortunately, having noraw() set IGNCR
* turned out to be too painful. So raw() now clears the COOKED_INPUT
* flags, but also clears (ICRNL|INLCR|IGNCR) which noraw() doesn't
* restore.
*
* Unfortunately, this means noraw() may still force some COOKED_INPUT
* flags on that the user had initially cleared via stty. It'll all
* come out in the wash when endwin() restores the user's original
* input bits (we hope...)
*
*/
#define COOKED_INPUT (IXON|IGNBRK|BRKINT|PARMRK)
int raw(void)
{
T(("raw() called"));
SP->_raw = TRUE;
SP->_cbreak = TRUE;
#ifdef TERMIOS
cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG|IEXTEN);
cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT|ICRNL|INLCR|IGNCR);
cur_term->Nttyb.c_oflag &= ~(OPOST);
cur_term->Nttyb.c_cc[VMIN] = 1;
cur_term->Nttyb.c_cc[VTIME] = 0;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags |= RAW;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int cbreak(void)
{
T(("cbreak() called"));
SP->_cbreak = TRUE;
#ifdef TERMIOS
cur_term->Nttyb.c_lflag &= ~ICANON;
cur_term->Nttyb.c_lflag |= ISIG;
cur_term->Nttyb.c_cc[VMIN] = 1;
cur_term->Nttyb.c_cc[VTIME] = 0;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags |= CBREAK;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int echo(void)
{
T(("echo() called"));
SP->_echo = TRUE;
#ifdef TERMIOS
cur_term->Nttyb.c_lflag |= ECHO;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags |= ECHO;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int nl(void)
{
T(("nl() called"));
SP->_nl = TRUE;
#ifdef TERMIOS
/* the code used to set IXON|IXOFF here, Ghod knows why... */
cur_term->Nttyb.c_iflag |= ICRNL;
cur_term->Nttyb.c_oflag |= OPOST|ONLCR;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags |= CRMOD;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int qiflush(void)
{
T(("qiflush() called"));
/*
* Note: this implementation may be wrong. See the comment under
* intrflush().
*/
#ifdef TERMIOS
cur_term->Nttyb.c_lflag &= ~(NOFLSH);
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
return ERR;
#endif
}
int noraw(void)
{
T(("noraw() called"));
SP->_raw = FALSE;
SP->_cbreak = FALSE;
#ifdef TERMIOS
cur_term->Nttyb.c_lflag |= ISIG|ICANON|IEXTEN;
cur_term->Nttyb.c_iflag |= COOKED_INPUT;
cur_term->Nttyb.c_oflag |= OPOST;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int nocbreak(void)
{
T(("nocbreak() called"));
SP->_cbreak = 0;
#ifdef TERMIOS
cur_term->Nttyb.c_lflag |= ICANON;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags &= ~CBREAK;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int noecho(void)
{
T(("noecho() called"));
SP->_echo = FALSE;
#ifdef TERMIOS
/*
* Turn off ECHONL to avoid having \n still be echoed when
* cooked mode is in effect (that is, ICANON is on).
*/
cur_term->Nttyb.c_lflag &= ~(ECHO|ECHONL);
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags &= ~ECHO;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int nonl(void)
{
T(("nonl() called"));
SP->_nl = FALSE;
#ifdef TERMIOS
cur_term->Nttyb.c_iflag &= ~ICRNL;
cur_term->Nttyb.c_oflag &= ~ONLCR;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
cur_term->Nttyb.sg_flags &= ~CRMOD;
stty(cur_term->Filedes, &cur_term->Nttyb);
return OK;
#endif
}
int noqiflush(void)
{
T(("noqiflush() called"));
/*
* Note: this implementation may be wrong. See the comment under
* intrflush().
*/
#ifdef TERMIOS
cur_term->Nttyb.c_lflag |= NOFLSH;
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
return ERR;
#endif
}
int intrflush(WINDOW *win, bool flag)
{
T(("intrflush() called"));
/*
* This call does the same thing as the qiflush()/noqiflush()
* pair. We know for certain that SVr3 intrflush() tweaks the
* NOFLSH bit; on the other hand, the match (in the SVr4 man
* pages) between the language describing NOFLSH in termio(7)
* and the language describing qiflush()/noqiflush() in
* curs_inopts(3x) is too exact to be coincidence.
*/
#ifdef TERMIOS
if (flag)
cur_term->Nttyb.c_lflag &= ~(NOFLSH);
else
cur_term->Nttyb.c_lflag |= (NOFLSH);
if((tcsetattr(cur_term->Filedes, TCSANOW, &cur_term->Nttyb)) == -1)
return ERR;
else
return OK;
#else
return ERR;
#endif
}
|