- 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;
+ }