ncursesw-morphos/ncurses/tinfo/lib_options.c

256 lines
6.2 KiB
C
Raw Normal View History

1998-03-01 12:21:12 +08:00
/****************************************************************************
2000-07-09 10:46:08 +08:00
* Copyright (c) 1998,1999,2000 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> *
****************************************************************************/
1997-05-15 12:00:00 +08:00
/*
** lib_options.c
**
** The routines to handle option setting.
**
*/
#include <curses.priv.h>
2000-07-09 10:46:08 +08:00
#include <term.h>
1997-05-15 12:00:00 +08:00
2000-10-21 12:42:11 +08:00
MODULE_ID("$Id: lib_options.c,v 1.40 2000/09/02 18:02:05 tom Exp $")
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
int
idlok(WINDOW *win, bool flag)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("idlok(%p,%d)"), win, flag));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (win) {
_nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region));
returnCode(OK);
} else
returnCode(ERR);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
void
idcok(WINDOW *win, bool flag)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("idcok(%p,%d)"), win, flag));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (win)
_nc_idcok = win->_idcok = (flag && has_ic());
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
returnVoid;
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
halfdelay(int t)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("halfdelay(%d)"), t));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (t < 1 || t > 255)
returnCode(ERR);
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
cbreak();
SP->_cbreak = t + 1;
returnCode(OK);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
nodelay(WINDOW *win, bool flag)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("nodelay(%p,%d)"), win, flag));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (win) {
if (flag == TRUE)
1998-03-01 12:21:12 +08:00
win->_delay = 0;
else
2000-07-09 10:46:08 +08:00
win->_delay = -1;
returnCode(OK);
} else
returnCode(ERR);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
notimeout(WINDOW *win, bool f)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("notimout(%p,%d)"), win, f));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (win) {
win->_notimeout = f;
returnCode(OK);
} else
returnCode(ERR);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
void
wtimeout(WINDOW *win, int delay)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("wtimeout(%p,%d)"), win, delay));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (win) {
win->_delay = delay;
}
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
keypad(WINDOW *win, bool flag)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("keypad(%p,%d)"), win, flag));
1997-05-15 12:00:00 +08:00
2000-07-09 10:46:08 +08:00
if (win) {
win->_use_keypad = flag;
returnCode(_nc_keypad(flag));
} else
returnCode(ERR);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
meta(WINDOW *win GCC_UNUSED, bool flag)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
/* Ok, we stay relaxed and don't signal an error if win is NULL */
T((T_CALLED("meta(%p,%d)"), win, flag));
SP->_use_meta = flag;
if (flag && meta_on) {
TPUTS_TRACE("meta_on");
putp(meta_on);
} else if (!flag && meta_off) {
TPUTS_TRACE("meta_off");
putp(meta_off);
}
returnCode(OK);
1997-05-15 12:00:00 +08:00
}
/* curs_set() moved here to narrow the kernel interface */
2000-07-09 10:46:08 +08:00
int
curs_set(int vis)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
int cursor = SP->_cursor;
T((T_CALLED("curs_set(%d)"), vis));
if (vis < 0 || vis > 2)
returnCode(ERR);
if (vis == cursor)
returnCode(cursor);
switch (vis) {
case 2:
if (cursor_visible) {
TPUTS_TRACE("cursor_visible");
putp(cursor_visible);
} else
returnCode(ERR);
break;
case 1:
if (cursor_normal) {
TPUTS_TRACE("cursor_normal");
putp(cursor_normal);
} else
returnCode(ERR);
break;
case 0:
if (cursor_invisible) {
TPUTS_TRACE("cursor_invisible");
putp(cursor_invisible);
} else
returnCode(ERR);
break;
}
SP->_cursor = vis;
_nc_flush();
returnCode(cursor == -1 ? 1 : cursor);
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
typeahead(int fd)
1997-05-15 12:00:00 +08:00
{
2000-07-09 10:46:08 +08:00
T((T_CALLED("typeahead(%d)"), fd));
SP->_checkfd = fd;
returnCode(OK);
1997-05-15 12:00:00 +08:00
}
/*
** has_key()
**
** Return TRUE if the current terminal has the given key
**
*/
2000-10-21 12:42:11 +08:00
#if NCURSES_EXT_FUNCS
2000-07-09 10:46:08 +08:00
static int
has_key_internal(int keycode, struct tries *tp)
1997-05-15 12:00:00 +08:00
{
1998-03-01 12:21:12 +08:00
if (tp == 0)
2000-07-09 10:46:08 +08:00
return (FALSE);
1997-05-15 12:00:00 +08:00
else if (tp->value == keycode)
2000-07-09 10:46:08 +08:00
return (TRUE);
1997-05-15 12:00:00 +08:00
else
2000-07-09 10:46:08 +08:00
return (has_key_internal(keycode, tp->child)
|| has_key_internal(keycode, tp->sibling));
1997-05-15 12:00:00 +08:00
}
2000-07-09 10:46:08 +08:00
int
has_key(int keycode)
1997-05-15 12:00:00 +08:00
{
T((T_CALLED("has_key(%d)"), keycode));
returnCode(has_key_internal(keycode, SP->_keytry));
}
1999-10-24 12:32:42 +08:00
#endif /* NCURSES_EXT_FUNCS */
1998-03-01 12:21:12 +08:00
/* Turn the keypad on/off
*
* Note: we flush the output because changing this mode causes some terminals
* to emit different escape sequences for cursor and keypad keys. If we don't
* flush, then the next wgetch may get the escape sequence that corresponds to
* the terminal state _before_ switching modes.
*/
2000-07-09 10:46:08 +08:00
int
_nc_keypad(bool flag)
1998-03-01 12:21:12 +08:00
{
2000-07-09 10:46:08 +08:00
if (flag && keypad_xmit) {
TPUTS_TRACE("keypad_xmit");
putp(keypad_xmit);
_nc_flush();
} else if (!flag && keypad_local) {
TPUTS_TRACE("keypad_local");
putp(keypad_local);
_nc_flush();
}
if (flag && !SP->_tried) {
_nc_init_keytry();
SP->_tried = TRUE;
}
return (OK);
1998-03-01 12:21:12 +08:00
}