X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_options.c;h=eb170354f4dc630e15509c8799edd4d4ac26f797;hp=bdb0b7024d7c6ae99276ee28da70b67387da6e55;hb=3ce60e9f58cc00309981ed711d0b0d3362105881;hpb=027ae42953e3186daed8f3882da73de48291b606;ds=sidebyside diff --git a/ncurses/tinfo/lib_options.c b/ncurses/tinfo/lib_options.c index bdb0b702..eb170354 100644 --- a/ncurses/tinfo/lib_options.c +++ b/ncurses/tinfo/lib_options.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -43,7 +43,10 @@ #include -MODULE_ID("$Id: lib_options.c,v 1.49 2006/03/04 19:28:25 tom Exp $") +MODULE_ID("$Id: lib_options.c,v 1.57 2008/06/28 23:31:15 tom Exp $") + +static int _nc_curs_set(SCREEN *, int); +static int _nc_meta(SCREEN *, bool); NCURSES_EXPORT(int) idlok(WINDOW *win, bool flag) @@ -126,7 +129,7 @@ keypad(WINDOW *win, bool flag) if (win) { win->_use_keypad = flag; - returnCode(_nc_keypad(flag)); + returnCode(_nc_keypad(SP, flag)); } else returnCode(ERR); } @@ -134,23 +137,11 @@ keypad(WINDOW *win, bool flag) NCURSES_EXPORT(int) meta(WINDOW *win GCC_UNUSED, bool flag) { - int result = ERR; + int result; /* Ok, we stay relaxed and don't signal an error if win is NULL */ T((T_CALLED("meta(%p,%d)"), win, flag)); - - if (SP != 0) { - 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); - } - result = OK; - } + result = _nc_meta(SP, flag); returnCode(result); } @@ -159,43 +150,10 @@ meta(WINDOW *win GCC_UNUSED, bool flag) NCURSES_EXPORT(int) curs_set(int vis) { - int result = ERR; + int result; T((T_CALLED("curs_set(%d)"), vis)); - if (SP != 0 && vis >= 0 && vis <= 2) { - int cursor = SP->_cursor; - - if (vis == cursor) { - result = cursor; - } else { - result = (cursor == -1 ? 1 : cursor); - switch (vis) { - case 2: - if (cursor_visible) { - TPUTS_TRACE("cursor_visible"); - putp(cursor_visible); - } else - result = ERR; - break; - case 1: - if (cursor_normal) { - TPUTS_TRACE("cursor_normal"); - putp(cursor_normal); - } else - result = ERR; - break; - case 0: - if (cursor_invisible) { - TPUTS_TRACE("cursor_invisible"); - putp(cursor_invisible); - } else - result = ERR; - break; - } - SP->_cursor = vis; - _nc_flush(); - } - } + result = _nc_curs_set(SP, vis); returnCode(result); } @@ -220,7 +178,7 @@ typeahead(int fd) #if NCURSES_EXT_FUNCS static int -has_key_internal(int keycode, struct tries *tp) +has_key_internal(int keycode, TRIES * tp) { if (tp == 0) return (FALSE); @@ -239,6 +197,35 @@ has_key(int keycode) } #endif /* NCURSES_EXT_FUNCS */ +/* + * 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; +} + /* Turn the keypad on/off * * Note: we flush the output because changing this mode causes some terminals @@ -247,24 +234,94 @@ has_key(int keycode) * the terminal state _before_ switching modes. */ NCURSES_EXPORT(int) -_nc_keypad(bool flag) +_nc_keypad(SCREEN *sp, bool flag) { - 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(); + int rc = ERR; + + 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(curses); + save_sp = SP; + _nc_set_screen(sp); + rc = _nc_keypad(sp, flag); + _nc_set_screen(save_sp); + _nc_unlock_global(curses); + } 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; + } } + 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) { - if (flag && !SP->_tried) { - _nc_init_keytry(); - SP->_tried = TRUE; + SP->_use_meta = flag; + + if (flag) { + _nc_putp("meta_on", meta_on); + } else { + _nc_putp("meta_off", meta_off); } - SP->_keypad_on = flag; + result = OK; } - return (OK); + return result; }