]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_set_term.c
ncurses 5.6 - patch 20080607
[ncurses.git] / ncurses / base / lib_set_term.c
index 3f84706016318dd48686599e56c5f9514087e43f..24f90d1b19a55e19c7a1539d71313213ad3a3c6f 100644 (file)
 #include <term.h>              /* cur_term */
 #include <tic.h>
 
-MODULE_ID("$Id: lib_set_term.c,v 1.106 2008/03/29 22:47:24 tom Exp $")
+MODULE_ID("$Id: lib_set_term.c,v 1.112 2008/06/07 22:29:07 tom Exp $")
 
 NCURSES_EXPORT(SCREEN *)
 set_term(SCREEN *screenp)
 {
     SCREEN *oldSP;
+    SCREEN *newSP;
 
     T((T_CALLED("set_term(%p)"), screenp));
 
-    _nc_lock_global(set_SP);
+    _nc_lock_global(curses);
 
     oldSP = SP;
     _nc_set_screen(screenp);
+    newSP = SP;
 
-    if (SP != 0) {
-       set_curterm(SP->_term);
+    if (newSP != 0) {
+       set_curterm(newSP->_term);
 #if !USE_REENTRANT
-       curscr = SP->_curscr;
-       newscr = SP->_newscr;
-       stdscr = SP->_stdscr;
-       COLORS = SP->_color_count;
-       COLOR_PAIRS = SP->_pair_count;
+       curscr = newSP->_curscr;
+       newscr = newSP->_newscr;
+       stdscr = newSP->_stdscr;
+       COLORS = newSP->_color_count;
+       COLOR_PAIRS = newSP->_pair_count;
 #endif
     } else {
        set_curterm(0);
@@ -78,7 +80,7 @@ set_term(SCREEN *screenp)
 #endif
     }
 
-    _nc_unlock_global(set_SP);
+    _nc_unlock_global(curses);
 
     T((T_RETURN("%p"), oldSP));
     return (oldSP);
@@ -94,26 +96,39 @@ _nc_free_keytry(TRIES * kt)
     }
 }
 
+static bool
+delink_screen(SCREEN *sp)
+{
+    SCREEN *last = 0;
+    SCREEN *temp;
+    bool result = FALSE;
+
+    for (each_screen(temp)) {
+       if (temp == sp) {
+           if (last)
+               last = sp->_next_screen;
+           else
+               _nc_screen_chain = sp->_next_screen;
+           result = TRUE;
+           break;
+       }
+       last = temp;
+    }
+    return result;
+}
+
 /*
  * Free the storage associated with the given SCREEN sp.
  */
 NCURSES_EXPORT(void)
 delscreen(SCREEN *sp)
 {
-    SCREEN **scan = &_nc_screen_chain;
     int i;
 
     T((T_CALLED("delscreen(%p)"), sp));
 
-    if (sp != 0) {
-       _nc_lock_global(set_SP);
-       while (*scan) {
-           if (*scan == sp) {
-               *scan = sp->_next_screen;
-               break;
-           }
-           scan = &(*scan)->_next_screen;
-       }
+    _nc_lock_global(curses);
+    if (delink_screen(sp)) {
 
        (void) _nc_freewin(sp->_curscr);
        (void) _nc_freewin(sp->_newscr);
@@ -149,7 +164,10 @@ delscreen(SCREEN *sp)
        FreeIfNeeded(sp->_acs_map);
        FreeIfNeeded(sp->_screen_acs_map);
 
+#if 0
+       /* FIXME - this should be a copy of the struct, not a pointer */
        del_curterm(sp->_term);
+#endif
 
        /*
         * If the associated output stream has been closed, we can discard the
@@ -180,8 +198,8 @@ delscreen(SCREEN *sp)
 #endif
            _nc_set_screen(0);
        }
-       _nc_unlock_global(set_SP);
     }
+    _nc_unlock_global(curses);
 
     returnVoid;
 }
@@ -199,7 +217,7 @@ no_mouse_inline(SCREEN *sp GCC_UNUSED)
 }
 
 static bool
-no_mouse_parse(int code GCC_UNUSED)
+no_mouse_parse(SCREEN *sp GCC_UNUSED, int code GCC_UNUSED)
 {
     return TRUE;
 }
@@ -267,7 +285,7 @@ _nc_setupscreen(int slines GCC_UNUSED,
     /*
      * We should always check the screensize, just in case.
      */
-    _nc_get_screensize(&slines, &scolumns);
+    _nc_get_screensize(SP, &slines, &scolumns);
     SET_LINES(slines);
     SET_COLS(scolumns);
     T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));