X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftinfo%2Flib_options.c;h=613c5d04fb3d787f28d117528e71e2f3835245c6;hp=05bd47685dd617543bd937d9f086667d24d9da7d;hb=ba78eb501a2ed01647123dbe7279ca0f38782e04;hpb=46722468f47c2b77b3987729b4bcf2321cccfd01 diff --git a/ncurses/tinfo/lib_options.c b/ncurses/tinfo/lib_options.c index 05bd4768..613c5d04 100644 --- a/ncurses/tinfo/lib_options.c +++ b/ncurses/tinfo/lib_options.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000,2001,2002 Free Software Foundation, Inc. * + * Copyright (c) 1998-2011,2013 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 * @@ -29,6 +29,8 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * + * and: Juergen Pfeifer 2009 * ****************************************************************************/ /* @@ -40,50 +42,67 @@ #include -#include +#ifndef CUR +#define CUR SP_TERMTYPE +#endif -MODULE_ID("$Id: lib_options.c,v 1.46 2002/02/02 19:40:54 tom Exp $") +MODULE_ID("$Id: lib_options.c,v 1.74 2013/01/12 16:44:17 tom Exp $") NCURSES_EXPORT(int) idlok(WINDOW *win, bool flag) { - T((T_CALLED("idlok(%p,%d)"), win, flag)); + int res = ERR; + T((T_CALLED("idlok(%p,%d)"), (void *) win, flag)); if (win) { - _nc_idlok = win->_idlok = (flag && (has_il() || change_scroll_region)); - returnCode(OK); - } else - returnCode(ERR); + SCREEN *sp = _nc_screen_of(win); + if (sp && IsTermInfo(sp)) { + sp->_nc_sp_idlok = + win->_idlok = (flag && (NCURSES_SP_NAME(has_il) (NCURSES_SP_ARG) + || change_scroll_region)); + res = OK; + } + } + returnCode(res); } NCURSES_EXPORT(void) idcok(WINDOW *win, bool flag) { - T((T_CALLED("idcok(%p,%d)"), win, flag)); - - if (win) - _nc_idcok = win->_idcok = (flag && has_ic()); + T((T_CALLED("idcok(%p,%d)"), (void *) win, flag)); + if (win) { + SCREEN *sp = _nc_screen_of(win); + sp->_nc_sp_idcok = win->_idcok = (flag && NCURSES_SP_NAME(has_ic) (NCURSES_SP_ARG)); + } returnVoid; } NCURSES_EXPORT(int) -halfdelay(int t) +NCURSES_SP_NAME(halfdelay) (NCURSES_SP_DCLx int t) { - T((T_CALLED("halfdelay(%d)"), t)); + T((T_CALLED("halfdelay(%p,%d)"), (void *) SP_PARM, t)); - if (t < 1 || t > 255) + if (t < 1 || t > 255 || !IsValidTIScreen(SP_PARM)) returnCode(ERR); - cbreak(); - SP->_cbreak = t + 1; + NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG); + SP_PARM->_cbreak = t + 1; returnCode(OK); } +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +halfdelay(int t) +{ + return NCURSES_SP_NAME(halfdelay) (CURRENT_SCREEN, t); +} +#endif + NCURSES_EXPORT(int) nodelay(WINDOW *win, bool flag) { - T((T_CALLED("nodelay(%p,%d)"), win, flag)); + T((T_CALLED("nodelay(%p,%d)"), (void *) win, flag)); if (win) { if (flag == TRUE) @@ -98,7 +117,7 @@ nodelay(WINDOW *win, bool flag) NCURSES_EXPORT(int) notimeout(WINDOW *win, bool f) { - T((T_CALLED("notimout(%p,%d)"), win, f)); + T((T_CALLED("notimeout(%p,%d)"), (void *) win, f)); if (win) { win->_notimeout = f; @@ -110,7 +129,7 @@ notimeout(WINDOW *win, bool f) NCURSES_EXPORT(void) wtimeout(WINDOW *win, int delay) { - T((T_CALLED("wtimeout(%p,%d)"), win, delay)); + T((T_CALLED("wtimeout(%p,%d)"), (void *) win, delay)); if (win) { win->_delay = delay; @@ -121,11 +140,11 @@ wtimeout(WINDOW *win, int delay) NCURSES_EXPORT(int) keypad(WINDOW *win, bool flag) { - T((T_CALLED("keypad(%p,%d)"), win, flag)); + T((T_CALLED("keypad(%p,%d)"), (void *) win, flag)); if (win) { win->_use_keypad = flag; - returnCode(_nc_keypad(flag)); + returnCode(_nc_keypad(_nc_screen_of(win), flag)); } else returnCode(ERR); } @@ -133,72 +152,102 @@ keypad(WINDOW *win, bool flag) NCURSES_EXPORT(int) meta(WINDOW *win GCC_UNUSED, bool flag) { + int result = ERR; + SCREEN *sp = (win == 0) ? CURRENT_SCREEN : _nc_screen_of(win); + /* Ok, we stay relaxed and don't signal an error if win is NULL */ - T((T_CALLED("meta(%p,%d)"), win, flag)); + T((T_CALLED("meta(%p,%d)"), (void *) win, flag)); - SP->_use_meta = flag; + /* Ok, we stay relaxed and don't signal an error if win is NULL */ - if (flag && meta_on) { - TPUTS_TRACE("meta_on"); - putp(meta_on); - } else if (!flag && meta_off) { - TPUTS_TRACE("meta_off"); - putp(meta_off); + if (sp != 0) { + sp->_use_meta = flag; +#ifdef USE_TERM_DRIVER + if (IsTermInfo(sp)) { + if (flag) { + NCURSES_PUTP2("meta_on", meta_on); + } else { + NCURSES_PUTP2("meta_off", meta_off); + } + } +#else + if (flag) { + NCURSES_PUTP2("meta_on", meta_on); + } else { + NCURSES_PUTP2("meta_off", meta_off); + } +#endif + result = OK; } - returnCode(OK); + returnCode(result); } /* curs_set() moved here to narrow the kernel interface */ NCURSES_EXPORT(int) -curs_set(int vis) +NCURSES_SP_NAME(curs_set) (NCURSES_SP_DCLx int vis) { - int cursor = SP->_cursor; + int code = ERR; + T((T_CALLED("curs_set(%p,%d)"), (void *) SP_PARM, vis)); + + if (SP_PARM != 0 && vis >= 0 && vis <= 2) { + int cursor = SP_PARM->_cursor; + bool bBuiltIn = !IsTermInfo(SP_PARM); + if (vis == cursor) { + code = cursor; + } else { + if (!bBuiltIn) { + switch (vis) { + case 2: + code = NCURSES_PUTP2_FLUSH("cursor_visible", + cursor_visible); + break; + case 1: + code = NCURSES_PUTP2_FLUSH("cursor_normal", + cursor_normal); + break; + case 0: + code = NCURSES_PUTP2_FLUSH("cursor_invisible", + cursor_invisible); + break; + } + } else + code = ERR; + if (code != ERR) + code = (cursor == -1 ? 1 : cursor); + SP_PARM->_cursor = vis; + } + } + returnCode(code); +} - T((T_CALLED("curs_set(%d)"), vis)); +#if NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +curs_set(int vis) +{ + return (NCURSES_SP_NAME(curs_set) (CURRENT_SCREEN, vis)); +} +#endif - if (vis < 0 || vis > 2) +NCURSES_EXPORT(int) +NCURSES_SP_NAME(typeahead) (NCURSES_SP_DCLx int fd) +{ + T((T_CALLED("typeahead(%p, %d)"), (void *) SP_PARM, fd)); + if (IsValidTIScreen(SP_PARM)) { + SP_PARM->_checkfd = fd; + returnCode(OK); + } else { 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); } +#if NCURSES_SP_FUNCS NCURSES_EXPORT(int) typeahead(int fd) { - T((T_CALLED("typeahead(%d)"), fd)); - SP->_checkfd = fd; - returnCode(OK); + return NCURSES_SP_NAME(typeahead) (CURRENT_SCREEN, fd); } +#endif /* ** has_key() @@ -209,7 +258,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); @@ -220,14 +269,50 @@ has_key_internal(int keycode, struct tries *tp) || has_key_internal(keycode, tp->sibling)); } +#ifdef USE_TERM_DRIVER +NCURSES_EXPORT(int) +TINFO_HAS_KEY(SCREEN *sp, int keycode) +{ + return IsValidTIScreen(sp) ? + has_key_internal(keycode, sp->_keytry) : 0; +} +#else +NCURSES_EXPORT(int) +NCURSES_SP_NAME(has_key) (NCURSES_SP_DCLx int keycode) +{ + T((T_CALLED("has_key(%p,%d)"), (void *) SP_PARM, keycode)); + returnCode(SP != 0 ? has_key_internal(keycode, SP_PARM->_keytry) : FALSE); +} + +#if NCURSES_SP_FUNCS NCURSES_EXPORT(int) has_key(int keycode) { - T((T_CALLED("has_key(%d)"), keycode)); - returnCode(has_key_internal(keycode, SP->_keytry)); + return NCURSES_SP_NAME(has_key) (CURRENT_SCREEN, keycode); } +#endif +#endif #endif /* NCURSES_EXT_FUNCS */ +NCURSES_EXPORT(int) +NCURSES_SP_NAME(_nc_putp_flush) (NCURSES_SP_DCLx + const char *name, const char *value) +{ + int rc = NCURSES_PUTP2(name, value); + if (rc != ERR) { + _nc_flush(); + } + return rc; +} + +#if 0 && NCURSES_SP_FUNCS +NCURSES_EXPORT(int) +_nc_putp_flush(const char *name, const char *value) +{ + return NCURSES_SP_NAME(_nc_putp_flush) (CURRENT_SCREEN, name, value); +} +#endif + /* Turn the keypad on/off * * Note: we flush the output because changing this mode causes some terminals @@ -236,22 +321,49 @@ has_key(int keycode) * the terminal state _before_ switching modes. */ NCURSES_EXPORT(int) -_nc_keypad(bool flag) +_nc_keypad(SCREEN *sp, int 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(); - } - - if (flag && !SP->_tried) { - _nc_init_keytry(); - SP->_tried = TRUE; + 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 (_nc_use_pthreads && sp != CURRENT_SCREEN) { + SCREEN *save_sp; + + /* cannot use use_screen(), since that is not in tinfo library */ + _nc_lock_global(curses); + save_sp = CURRENT_SCREEN; + _nc_set_screen(sp); + rc = _nc_keypad(sp, flag); + _nc_set_screen(save_sp); + _nc_unlock_global(curses); + } else +#endif + { +#ifdef USE_TERM_DRIVER + rc = CallDriver_1(sp, kpad, flag); + if (rc == OK) + sp->_keypad_on = flag; +#else + if (flag) { + (void) NCURSES_PUTP2_FLUSH("keypad_xmit", keypad_xmit); + } else if (!flag && keypad_local) { + (void) NCURSES_PUTP2_FLUSH("keypad_local", keypad_local); + } + + if (flag && !sp->_tried) { + _nc_init_keytry(sp); + sp->_tried = TRUE; + } + sp->_keypad_on = flag; + rc = OK; +#endif + } } - SP->_keypad_on = flag; - return (OK); + return (rc); }