2 /***************************************************************************
4 ****************************************************************************
5 * ncurses is copyright (C) 1992-1995 *
7 * zmbenhal@netcom.com *
9 * esr@snark.thyrsus.com *
11 * Permission is hereby granted to reproduce and distribute ncurses *
12 * by any means and for any fee, whether alone or as part of a *
13 * larger distribution, in source or in binary form, PROVIDED *
14 * this notice is included with any such distribution, and is not *
15 * removed from any of its header files. Mention of ncurses in any *
16 * applications linked with it is highly appreciated. *
18 * ncurses comes AS IS with no warranty, implied or expressed. *
20 ***************************************************************************/
41 #include <curses.priv.h>
42 #include <term.h> /* cur_term */
44 MODULE_ID("$Id: lib_raw.c,v 1.16 1997/02/02 00:02:32 tom Exp $")
51 #include <sys/termio.h> /* needed for ISC */
54 /* may be undefined if we're using termio.h */
62 #define COOKED_INPUT (IXON|BRKINT|PARMRK)
65 char *_tracebits(void)
66 /* describe the state of the terminal control bits exactly */
68 static char buf[BUFSIZ];
69 static const struct {unsigned int val; const char *name;}
86 #define ALLIN (BRKINT|IGNBRK|IGNPAR|PARMRK|INPCK|ISTRIP|INLCR|IGNCR|ICRNL|IXON|IXOFF)
92 #define ALLOUT (OPOST)
102 {PARODD|PARENB, "PARODD"}, /* concession to readability */
104 #define ALLCTRL (CLOCAL|CREAD|CSIZE|CSTOPB|HUPCL|PARENB|PARODD)
109 {ECHOE|ECHO, "ECHOE"}, /* concession to readability */
110 {ECHOK|ECHO, "ECHOK"}, /* concession to readability */
122 #define ALLLOCAL (ECHO|ECHONL|ICANON|ISIG|NOFLSH|TOSTOP|IEXTEN)
126 if (cur_term->Nttyb.c_iflag & ALLIN)
128 (void) strcpy(buf, "iflags: {");
129 for (sp = iflags; sp->val; sp++)
130 if ((cur_term->Nttyb.c_iflag & sp->val) == sp->val)
132 (void) strcat(buf, sp->name);
133 (void) strcat(buf, ", ");
135 if (buf[strlen(buf) - 2] == ',')
136 buf[strlen(buf) - 2] = '\0';
137 (void) strcat(buf,"} ");
140 if (cur_term->Nttyb.c_oflag & ALLOUT)
142 (void) strcat(buf, "oflags: {");
143 for (sp = oflags; sp->val; sp++)
144 if ((cur_term->Nttyb.c_oflag & sp->val) == sp->val)
146 (void) strcat(buf, sp->name);
147 (void) strcat(buf, ", ");
149 if (buf[strlen(buf) - 2] == ',')
150 buf[strlen(buf) - 2] = '\0';
151 (void) strcat(buf,"} ");
154 if (cur_term->Nttyb.c_cflag & ALLCTRL)
156 (void) strcat(buf, "cflags: {");
157 for (sp = cflags; sp->val; sp++)
158 if ((cur_term->Nttyb.c_cflag & sp->val) == sp->val)
160 (void) strcat(buf, sp->name);
161 (void) strcat(buf, ", ");
163 if (buf[strlen(buf) - 2] == ',')
164 buf[strlen(buf) - 2] = '\0';
165 (void) strcat(buf,"} ");
168 if (cur_term->Nttyb.c_lflag & ALLLOCAL)
170 (void) strcat(buf, "lflags: {");
171 for (sp = lflags; sp->val; sp++)
172 if ((cur_term->Nttyb.c_lflag & sp->val) == sp->val)
174 (void) strcat(buf, sp->name);
175 (void) strcat(buf, ", ");
177 if (buf[strlen(buf) - 2] == ',')
178 buf[strlen(buf) - 2] = '\0';
179 (void) strcat(buf,"} ");
183 /* reference: ttcompat(4M) on SunOS 4.1 */
207 {LLITOUT, "LLITOUT"},
213 #define ALLCTRL (CBREAK|CRMOD|ECHO|EVENP|LCASE|LLITOUT|ODDP|RAW|TANDEM|XTABS)
217 if (cur_term->Nttyb.sg_flags & ALLCTRL)
219 (void) strcat(buf, "cflags: {");
220 for (sp = cflags; sp->val; sp++)
221 if ((cur_term->Nttyb.sg_flags & sp->val) == sp->val)
223 (void) strcat(buf, sp->name);
224 (void) strcat(buf, ", ");
226 if (buf[strlen(buf) - 2] == ',')
227 buf[strlen(buf) - 2] = '\0';
228 (void) strcat(buf,"} ");
235 #define BEFORE(N) if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _tracebits())
236 #define AFTER(N) if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _tracebits())
244 T((T_CALLED("raw()")));
251 cur_term->Nttyb.c_lflag &= ~(ICANON|ISIG);
252 cur_term->Nttyb.c_iflag &= ~(COOKED_INPUT);
253 cur_term->Nttyb.c_cc[VMIN] = 1;
254 cur_term->Nttyb.c_cc[VTIME] = 0;
257 cur_term->Nttyb.sg_flags |= RAW;
259 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
266 T((T_CALLED("cbreak()")));
272 cur_term->Nttyb.c_lflag &= ~ICANON;
273 cur_term->Nttyb.c_iflag &= ~ICRNL;
274 cur_term->Nttyb.c_lflag |= ISIG;
275 cur_term->Nttyb.c_cc[VMIN] = 1;
276 cur_term->Nttyb.c_cc[VTIME] = 0;
279 cur_term->Nttyb.sg_flags |= CBREAK;
281 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
288 T((T_CALLED("echo()")));
298 T((T_CALLED("nl()")));
308 T((T_CALLED("qiflush()")));
311 * Note: this implementation may be wrong. See the comment under
317 cur_term->Nttyb.c_lflag &= ~(NOFLSH);
319 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
331 T((T_CALLED("noraw()")));
338 cur_term->Nttyb.c_lflag |= ISIG|ICANON;
339 cur_term->Nttyb.c_iflag |= COOKED_INPUT;
342 cur_term->Nttyb.sg_flags &= ~(RAW|CBREAK);
344 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
352 T((T_CALLED("nocbreak()")));
358 cur_term->Nttyb.c_lflag |= ICANON;
359 cur_term->Nttyb.c_iflag |= ICRNL;
362 cur_term->Nttyb.sg_flags &= ~CBREAK;
364 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
371 T((T_CALLED("noecho()")));
379 T((T_CALLED("nonl()")));
388 T((T_CALLED("noqiflush()")));
391 * Note: this implementation may be wrong. See the comment under
397 cur_term->Nttyb.c_lflag |= NOFLSH;
399 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)
408 int intrflush(WINDOW *win GCC_UNUSED, bool flag)
410 T((T_CALLED("intrflush(%d)"), flag));
413 * This call does the same thing as the qiflush()/noqiflush()
414 * pair. We know for certain that SVr3 intrflush() tweaks the
415 * NOFLSH bit; on the other hand, the match (in the SVr4 man
416 * pages) between the language describing NOFLSH in termio(7)
417 * and the language describing qiflush()/noqiflush() in
418 * curs_inopts(3x) is too exact to be coincidence.
424 cur_term->Nttyb.c_lflag &= ~(NOFLSH);
426 cur_term->Nttyb.c_lflag |= (NOFLSH);
428 if ((SET_TTY(cur_term->Filedes, &cur_term->Nttyb)) == -1)