]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/tinfo/lib_options.c
ncurses 5.7 - patch 20090606
[ncurses.git] / ncurses / tinfo / lib_options.c
index fc3dc42bca41710d38f39676f7a670df23ca3eec..f22d6c5c2fc617adc7a1511b5347a71040fe8591 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998,1999,2000 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2008,2009 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 <zmbenhal@netcom.com> 1992,1995               *
  *     and: Eric S. Raymond <esr@snark.thyrsus.com>                         *
+ *     and: Thomas E. Dickey                        1996-on                 *
+ *     and: Juergen Pfeifer                         2009                    *
  ****************************************************************************/
 
 /*
 
 #include <term.h>
 
-MODULE_ID("$Id: lib_options.c,v 1.40 2000/09/02 18:02:05 tom Exp $")
+#ifndef CUR
+#define CUR SP_TERMTYPE
+#endif
 
-int
+MODULE_ID("$Id: lib_options.c,v 1.64 2009/05/23 23:58:07 tom Exp $")
+
+static int _nc_meta(SCREEN *, bool);
+
+NCURSES_EXPORT(int)
 idlok(WINDOW *win, bool flag)
 {
+#if NCURSES_SP_FUNCS
+    SCREEN *sp = CURRENT_SCREEN;
+#endif
     T((T_CALLED("idlok(%p,%d)"), win, flag));
 
     if (win) {
@@ -56,7 +67,7 @@ idlok(WINDOW *win, bool flag)
        returnCode(ERR);
 }
 
-void
+NCURSES_EXPORT(void)
 idcok(WINDOW *win, bool flag)
 {
     T((T_CALLED("idcok(%p,%d)"), win, flag));
@@ -67,20 +78,28 @@ idcok(WINDOW *win, bool flag)
     returnVoid;
 }
 
-int
-halfdelay(int t)
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(halfdelay) (NCURSES_SP_DCLx int t)
 {
     T((T_CALLED("halfdelay(%d)"), t));
 
-    if (t < 1 || t > 255)
+    if (t < 1 || t > 255 || SP_PARM == 0)
        returnCode(ERR);
 
     cbreak();
-    SP->_cbreak = t + 1;
+    SP_PARM->_cbreak = t + 1;
     returnCode(OK);
 }
 
-int
+#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));
@@ -95,10 +114,10 @@ nodelay(WINDOW *win, bool flag)
        returnCode(ERR);
 }
 
-int
+NCURSES_EXPORT(int)
 notimeout(WINDOW *win, bool f)
 {
-    T((T_CALLED("notimout(%p,%d)"), win, f));
+    T((T_CALLED("notimeout(%p,%d)"), win, f));
 
     if (win) {
        win->_notimeout = f;
@@ -107,7 +126,7 @@ notimeout(WINDOW *win, bool f)
        returnCode(ERR);
 }
 
-void
+NCURSES_EXPORT(void)
 wtimeout(WINDOW *win, int delay)
 {
     T((T_CALLED("wtimeout(%p,%d)"), win, delay));
@@ -115,89 +134,92 @@ wtimeout(WINDOW *win, int delay)
     if (win) {
        win->_delay = delay;
     }
+    returnVoid;
 }
 
-int
+NCURSES_EXPORT(int)
 keypad(WINDOW *win, bool flag)
 {
     T((T_CALLED("keypad(%p,%d)"), win, flag));
 
     if (win) {
        win->_use_keypad = flag;
-       returnCode(_nc_keypad(flag));
+       returnCode(_nc_keypad(SP, flag));
     } else
        returnCode(ERR);
 }
 
-int
+NCURSES_EXPORT(int)
 meta(WINDOW *win GCC_UNUSED, bool flag)
 {
+    int result;
+
     /* 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);
+    returnCode(result);
+}
 
-    SP->_use_meta = flag;
+/* curs_set() moved here to narrow the kernel interface */
 
-    if (flag && meta_on) {
-       TPUTS_TRACE("meta_on");
-       putp(meta_on);
-    } else if (!flag && meta_off) {
-       TPUTS_TRACE("meta_off");
-       putp(meta_off);
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(curs_set) (NCURSES_SP_DCLx int vis)
+{
+    int result = ERR;
+
+    T((T_CALLED("curs_set(%p,%d)"), SP_PARM, vis));
+    if (SP_PARM != 0 && vis >= 0 && vis <= 2) {
+       int cursor = SP_PARM->_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_PARM->_cursor = vis;
+       }
     }
-    returnCode(OK);
+    returnCode(result);
 }
 
-/* curs_set() moved here to narrow the kernel interface */
-
-int
+#if NCURSES_SP_FUNCS
+NCURSES_EXPORT(int)
 curs_set(int vis)
 {
-    int cursor = SP->_cursor;
-
-    T((T_CALLED("curs_set(%d)"), 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(%d)"), fd));
+    if (SP_PARM != 0) {
+       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);
 }
 
-int
+#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()
@@ -208,7 +230,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);
@@ -216,17 +238,51 @@ has_key_internal(int keycode, struct tries *tp)
        return (TRUE);
     else
        return (has_key_internal(keycode, tp->child)
-           || has_key_internal(keycode, tp->sibling));
+               || has_key_internal(keycode, tp->sibling));
 }
 
-int
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(has_key) (NCURSES_SP_DCLx int keycode)
+{
+    T((T_CALLED("has_key(%p,%d)"), 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 /* NCURSES_EXT_FUNCS */
 
+/*
+ * Internal entrypoints use SCREEN* parameter to obtain capabilities rather
+ * than cur_term.
+ */
+#undef CUR
+#define CUR SP_TERMTYPE
+
+NCURSES_EXPORT(int)
+NCURSES_SP_NAME(_nc_putp_flush) (NCURSES_SP_DCLx
+                                const char *name, const char *value)
+{
+    int rc = _nc_putp(name, value);
+    if (rc != ERR) {
+       _nc_flush();
+    }
+    return rc;
+}
+
+#if 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
@@ -234,22 +290,64 @@ has_key(int keycode)
  * flush, then the next wgetch may get the escape sequence that corresponds to
  * the terminal state _before_ switching modes.
  */
-int
-_nc_keypad(bool flag)
+NCURSES_EXPORT(int)
+_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 (_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
+       {
+           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_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 && !SP->_tried) {
-       _nc_init_keytry();
-       SP->_tried = TRUE;
+       if (flag) {
+           _nc_putp("meta_on", meta_on);
+       } else {
+           _nc_putp("meta_off", meta_off);
+       }
+       result = OK;
     }
-    return (OK);
+    return result;
 }