ncursesw-morphos/ncurses/tinfo/lib_options.c

328 lines
7.8 KiB
C
Raw Normal View History

1998-03-01 12:21:12 +08:00
/****************************************************************************
* Copyright (c) 1998-2006,2008 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> *
2005-10-10 02:41:57 +08:00
* and: Thomas E. Dickey 1996-on *
1998-03-01 12:21:12 +08:00
****************************************************************************/
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
MODULE_ID("$Id: lib_options.c,v 1.55 2008/05/25 00:32:17 tom Exp $")
static int _nc_curs_set(SCREEN *, int);
static int _nc_meta(SCREEN *, bool);
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
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
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(void)
2000-07-09 10:46:08 +08:00
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
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
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
2004-02-09 10:15:26 +08:00
if (t < 1 || t > 255 || SP == 0)
2000-07-09 10:46:08 +08:00
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
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
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
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
notimeout(WINDOW *win, bool f)
1997-05-15 12:00:00 +08:00
{
2006-12-18 12:32:42 +08:00
T((T_CALLED("notimeout(%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
}
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(void)
2000-07-09 10:46:08 +08:00
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;
}
2002-10-13 11:35:53 +08:00
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
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(SP, flag));
2000-07-09 10:46:08 +08:00
} else
returnCode(ERR);
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
meta(WINDOW *win GCC_UNUSED, bool flag)
1997-05-15 12:00:00 +08:00
{
int result;
2004-02-09 10:15:26 +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));
result = _nc_meta(SP, flag);
2004-02-09 10:15:26 +08:00
returnCode(result);
1997-05-15 12:00:00 +08:00
}
/* curs_set() moved here to narrow the kernel interface */
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
2000-07-09 10:46:08 +08:00
curs_set(int vis)
1997-05-15 12:00:00 +08:00
{
int result;
2000-07-09 10:46:08 +08:00
T((T_CALLED("curs_set(%d)"), vis));
result = _nc_curs_set(SP, vis);
2005-10-10 02:41:57 +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
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));
2004-02-09 10:15:26 +08:00
if (SP != 0) {
SP->_checkfd = fd;
returnCode(OK);
} else {
returnCode(ERR);
}
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, 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)
2002-10-13 11:35:53 +08:00
|| has_key_internal(keycode, tp->sibling));
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
has_key(int keycode)
1997-05-15 12:00:00 +08:00
{
T((T_CALLED("has_key(%d)"), keycode));
2004-02-09 10:15:26 +08:00
returnCode(SP != 0 ? has_key_internal(keycode, SP->_keytry) : FALSE);
1997-05-15 12:00:00 +08:00
}
1999-10-24 12:32:42 +08:00
#endif /* NCURSES_EXT_FUNCS */
1998-03-01 12:21:12 +08:00
/*
* Internal entrypoints use SCREEN* parameter to obtain capabilities rather
* than cur_term.
*/
#undef CUR
#define CUR (sp->_term)->type.
static int
_nc_putp(const char *name GCC_UNUSED, const char *value)
{
int rc = ERR;
if (value) {
TPUTS_TRACE(name);
rc = putp(value);
}
return rc;
}
static int
_nc_putp_flush(const char *name, const char *value)
{
int rc = _nc_putp(name, value);
if (rc != ERR) {
_nc_flush();
}
return rc;
}
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.
*/
2002-10-13 11:35:53 +08:00
NCURSES_EXPORT(int)
_nc_keypad(SCREEN *sp, bool flag)
1998-03-01 12:21:12 +08:00
{
int rc = ERR;
2000-07-09 10:46:08 +08:00
if (sp != 0) {
#ifdef USE_PTHREADS
/*
* We might have this situation in a multithreaded application that
* has wgetch() reading in more than one thread. putp() and below
* may use SP explicitly.
*/
if (sp != SP) {
SCREEN *save_sp;
/* cannot use use_screen(), since that is not in tinfo library */
_nc_lock_global(use_screen);
save_sp = SP;
SP = sp;
rc = _nc_keypad(sp, flag);
SP = save_sp;
_nc_unlock_global(use_screen);
} else
#endif
{
if (flag) {
(void) _nc_putp_flush("keypad_xmit", keypad_xmit);
} else if (!flag && keypad_local) {
(void) _nc_putp_flush("keypad_local", keypad_local);
}
if (flag && !sp->_tried) {
_nc_init_keytry(sp);
sp->_tried = TRUE;
}
sp->_keypad_on = flag;
rc = OK;
2005-10-10 02:41:57 +08:00
}
2000-07-09 10:46:08 +08:00
}
return (rc);
}
static int
_nc_curs_set(SCREEN *sp, int vis)
{
int result = ERR;
T((T_CALLED("curs_set(%d)"), vis));
if (sp != 0 && vis >= 0 && vis <= 2) {
int cursor = sp->_cursor;
if (vis == cursor) {
result = cursor;
} else {
switch (vis) {
case 2:
result = _nc_putp_flush("cursor_visible", cursor_visible);
break;
case 1:
result = _nc_putp_flush("cursor_normal", cursor_normal);
break;
case 0:
result = _nc_putp_flush("cursor_invisible", cursor_invisible);
break;
}
if (result != ERR)
result = (cursor == -1 ? 1 : cursor);
sp->_cursor = vis;
}
}
returnCode(result);
}
static int
_nc_meta(SCREEN *sp, bool flag)
{
int result = ERR;
/* Ok, we stay relaxed and don't signal an error if win is NULL */
if (SP != 0) {
SP->_use_meta = flag;
if (flag) {
_nc_putp("meta_on", meta_on);
} else {
_nc_putp("meta_off", meta_off);
}
result = OK;
}
return result;
1998-03-01 12:21:12 +08:00
}