ncursesw-morphos/ncurses/tinfo/lib_raw.c

297 lines
7.0 KiB
C
Raw Normal View History

1998-03-01 12:21:12 +08:00
/****************************************************************************
2002-10-13 11:35:53 +08:00
* Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. *
1998-03-01 12:21:12 +08:00
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the *
* "Software"), to deal in the Software without restriction, including *
* without limitation the rights to use, copy, modify, merge, publish, *
* distribute, distribute with modifications, sublicense, and/or sell *
* copies of the Software, and to permit persons to whom the Software is *
* furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included *
* in all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
* IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
* THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
* Except as contained in this notice, the name(s) of the above copyright *
* holders shall not be used in advertising or otherwise to promote the *
* sale, use or other dealings in this Software without prior written *
* authorization. *
****************************************************************************/
/****************************************************************************
* Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
2002-10-13 11:35:53 +08:00
* and: Thomas E. Dickey 1998 on *
1998-03-01 12:21:12 +08:00
****************************************************************************/
1997-05-15 12:00:00 +08:00
/*
* raw.c
*
* Routines:
* raw()
* cbreak()
* noraw()
* nocbreak()
* qiflush()
* noqiflush()
* intrflush()
*
*/
#include <curses.priv.h>
2000-07-09 10:46:08 +08:00
#include <term.h> /* cur_term */
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
MODULE_ID("$Id: lib_raw.c,v 1.13 2002/07/06 22:00:45 tom Exp $")
1997-05-15 12:00:00 +08:00
2000-10-21 12:42:11 +08:00
#if SVR4_TERMIO && !defined(_POSIX_SOURCE)
1997-05-15 12:00:00 +08:00
#define _POSIX_SOURCE
#endif
#if HAVE_SYS_TERMIO_H
2000-07-09 10:46:08 +08:00
#include <sys/termio.h> /* needed for ISC */
1997-05-15 12:00:00 +08:00
#endif
1998-03-01 12:21:12 +08:00
#ifdef __EMX__
#include <io.h>
2002-10-13 11:35:53 +08:00
#define _nc_setmode(mode) setmode(SP->_ifd, mode)
#else
#define _nc_setmode(mode) /* nothing */
1998-03-01 12:21:12 +08:00
#endif
1997-05-15 12:00:00 +08:00
#define COOKED_INPUT (IXON|BRKINT|PARMRK)
#ifdef TRACE
1999-10-24 12:32:42 +08:00
#define BEFORE(N) if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits())
#define AFTER(N) if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits())
1997-05-15 12:00:00 +08:00
#else
#define BEFORE(s)
#define AFTER(s)
#endif /* TRACE */
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
raw(void)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("raw()")));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (SP != 0 && cur_term != 0) {
TTY buf;
1998-03-01 12:21:12 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("raw");
_nc_setmode(O_BINARY);
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
buf.c_lflag &= ~(ICANON | ISIG | IEXTEN);
buf.c_iflag &= ~(COOKED_INPUT);
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
1997-05-15 12:00:00 +08:00
#else
2002-10-13 11:35:53 +08:00
buf.sg_flags |= RAW;
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if ((result = _nc_set_tty_mode(&buf)) == OK) {
SP->_raw = TRUE;
SP->_cbreak = 1;
cur_term->Nttyb = buf;
}
AFTER("raw");
2000-07-09 10:46:08 +08:00
}
2002-10-13 11:35:53 +08:00
returnCode(result);
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
cbreak(void)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("cbreak()")));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (SP != 0 && cur_term != 0) {
TTY buf;
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("cbreak");
_nc_setmode(O_BINARY);
1998-03-01 12:21:12 +08:00
2002-10-13 11:35:53 +08:00
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
buf.c_lflag &= ~ICANON;
buf.c_iflag &= ~ICRNL;
buf.c_lflag |= ISIG;
buf.c_cc[VMIN] = 1;
buf.c_cc[VTIME] = 0;
1997-05-15 12:00:00 +08:00
#else
2002-10-13 11:35:53 +08:00
buf.sg_flags |= CBREAK;
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if ((result = _nc_set_tty_mode(&buf)) == OK) {
SP->_cbreak = 1;
cur_term->Nttyb = buf;
}
AFTER("cbreak");
}
returnCode(result);
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
/*
* Note:
* this implementation may be wrong. See the comment under intrflush().
*/
NCURSES_EXPORT(void)
2000-07-09 10:46:08 +08:00
qiflush(void)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("qiflush()")));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (cur_term != 0) {
TTY buf;
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("qiflush");
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
buf.c_lflag &= ~(NOFLSH);
result = _nc_set_tty_mode(&buf);
#else
/* FIXME */
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if (result == OK)
cur_term->Nttyb = buf;
AFTER("qiflush");
}
returnVoid;
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
noraw(void)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("noraw()")));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (SP != 0 && cur_term != 0) {
TTY buf;
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("noraw");
_nc_setmode(O_TEXT);
1998-03-01 12:21:12 +08:00
2002-10-13 11:35:53 +08:00
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
buf.c_lflag |= ISIG | ICANON |
(cur_term->Ottyb.c_lflag & IEXTEN);
buf.c_iflag |= COOKED_INPUT;
1997-05-15 12:00:00 +08:00
#else
2002-10-13 11:35:53 +08:00
buf.sg_flags &= ~(RAW | CBREAK);
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if ((result = _nc_set_tty_mode(&buf)) == OK) {
SP->_raw = FALSE;
SP->_cbreak = 0;
cur_term->Nttyb = buf;
}
AFTER("noraw");
}
returnCode(result);
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
nocbreak(void)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("nocbreak()")));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (SP != 0 && cur_term != 0) {
TTY buf;
1998-03-01 12:21:12 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("nocbreak");
_nc_setmode(O_TEXT);
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
buf.c_lflag |= ICANON;
buf.c_iflag |= ICRNL;
1997-05-15 12:00:00 +08:00
#else
2002-10-13 11:35:53 +08:00
buf.sg_flags &= ~CBREAK;
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if ((result = _nc_set_tty_mode(&buf)) == OK) {
SP->_cbreak = 0;
cur_term->Nttyb = buf;
}
AFTER("nocbreak");
}
returnCode(result);
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
/*
* Note:
* this implementation may be wrong. See the comment under intrflush().
*/
NCURSES_EXPORT(void)
2000-07-09 10:46:08 +08:00
noqiflush(void)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("noqiflush()")));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (cur_term != 0) {
TTY buf;
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("noqiflush");
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
buf.c_lflag |= NOFLSH;
result = _nc_set_tty_mode(&buf);
#else
/* FIXME */
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if (result == OK) {
cur_term->Nttyb = buf;
}
AFTER("noqiflush");
}
returnVoid;
1997-05-15 12:00:00 +08:00
}
2002-10-13 11:35:53 +08:00
/*
* 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.
*/
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
intrflush(WINDOW *win GCC_UNUSED, bool flag)
1997-05-15 12:00:00 +08:00
{
2002-10-13 11:35:53 +08:00
int result = ERR;
2000-07-09 10:46:08 +08:00
T((T_CALLED("intrflush(%d)"), flag));
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
if (cur_term != 0) {
TTY buf;
1997-05-15 12:00:00 +08:00
2002-10-13 11:35:53 +08:00
BEFORE("intrflush");
buf = cur_term->Nttyb;
1997-05-15 12:00:00 +08:00
#ifdef TERMIOS
2002-10-13 11:35:53 +08:00
if (flag)
buf.c_lflag &= ~(NOFLSH);
else
buf.c_lflag |= (NOFLSH);
result = _nc_set_tty_mode(&buf);
1997-05-15 12:00:00 +08:00
#else
2002-10-13 11:35:53 +08:00
/* FIXME */
1997-05-15 12:00:00 +08:00
#endif
2002-10-13 11:35:53 +08:00
if (result == OK) {
cur_term->Nttyb = buf;
}
AFTER("intrflush");
}
returnCode(result);
1997-05-15 12:00:00 +08:00
}