]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - ncurses/base/lib_set_term.c
ncurses 6.0 - patch 20170401
[ncurses.git] / ncurses / base / lib_set_term.c
index 13b0772862df09e96ff0c8ba4b345201550b6818..8d475b968e1bb55de64b1a458fd623eecc971f08 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2016,2017 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            *
@@ -47,7 +47,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_set_term.c,v 1.151 2015/04/18 22:08:18 tom Exp $")
+MODULE_ID("$Id: lib_set_term.c,v 1.158 2017/04/01 13:51:59 tom Exp $")
 
 #ifdef USE_TERM_DRIVER
 #define MaxColors      InfoOf(sp).maxcolors
@@ -134,7 +134,6 @@ delink_screen(SCREEN *sp)
 NCURSES_EXPORT(void)
 delscreen(SCREEN *sp)
 {
-    int i;
 
     T((T_CALLED("delscreen(%p)"), (void *) sp));
 
@@ -159,7 +158,10 @@ delscreen(SCREEN *sp)
        (void) _nc_freewin(StdScreen(sp));
 
        if (sp->_slk != 0) {
+
            if (sp->_slk->ent != 0) {
+               int i;
+
                for (i = 0; i < sp->_slk->labcnt; ++i) {
                    FreeIfNeeded(sp->_slk->ent[i].ent_text);
                    FreeIfNeeded(sp->_slk->ent[i].form_text);
@@ -190,6 +192,7 @@ delscreen(SCREEN *sp)
 
        NCURSES_SP_NAME(_nc_flush) (NCURSES_SP_ARG);
        NCURSES_SP_NAME(del_curterm) (NCURSES_SP_ARGx sp->_term);
+       FreeIfNeeded(sp->out_buffer);
        free(sp);
 
        /*
@@ -206,6 +209,12 @@ delscreen(SCREEN *sp)
            COLOR_PAIRS = 0;
 #endif
            _nc_set_screen(0);
+#if USE_WIDEC_SUPPORT
+           if (SP == 0) {
+               FreeIfNeeded(_nc_wacs);
+               _nc_wacs = 0;
+           }
+#endif
        }
     }
     _nc_unlock_global(curses);
@@ -262,7 +271,7 @@ extract_fgbg(const char *src, int *result)
 }
 #endif
 
-#define ReturnScreenError() { _nc_set_screen(0); \
+#define ReturnScreenError() do { _nc_set_screen(0); \
                             returnCode(ERR); } while (0)
 
 /* OS-independent screen initializations */
@@ -277,9 +286,11 @@ NCURSES_SP_NAME(_nc_setupscreen) (
                                     int filtered,
                                     int slk_format)
 {
+#ifndef USE_TERM_DRIVER
+    static const TTY null_TTY; /* all zeros iff uninitialized */
+#endif
     char *env;
     int bottom_stolen = 0;
-    ripoff_t *rop;
     SCREEN *sp;
 #ifndef USE_TERM_DRIVER
     bool support_cookies = USE_XMC_SUPPORT;
@@ -296,6 +307,7 @@ NCURSES_SP_NAME(_nc_setupscreen) (
 
     if (!sp) {
        sp = _nc_alloc_screen_sp();
+       T(("_nc_alloc_screen_sp %p", sp));
        *spp = sp;
     }
     if (!sp
@@ -412,8 +424,8 @@ NCURSES_SP_NAME(_nc_setupscreen) (
     sp->_default_fg = COLOR_WHITE;
     sp->_default_bg = COLOR_BLACK;
 #else
-    sp->_default_fg = C_MASK;
-    sp->_default_bg = C_MASK;
+    sp->_default_fg = COLOR_DEFAULT;
+    sp->_default_bg = COLOR_DEFAULT;
 #endif
 
     /*
@@ -425,9 +437,9 @@ NCURSES_SP_NAME(_nc_setupscreen) (
        char sep1, sep2;
        int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
        if (count >= 1) {
-           sp->_default_fg = ((fg >= 0 && fg < MaxColors) ? fg : C_MASK);
+           sp->_default_fg = ((fg >= 0 && fg < MaxColors) ? fg : COLOR_DEFAULT);
            if (count >= 3) {
-               sp->_default_bg = ((bg >= 0 && bg < MaxColors) ? bg : C_MASK);
+               sp->_default_bg = ((bg >= 0 && bg < MaxColors) ? bg : COLOR_DEFAULT);
            }
            TR(TRACE_CHARPUT | TRACE_MOVE,
               ("from environment assumed fg=%d, bg=%d",
@@ -574,7 +586,9 @@ NCURSES_SP_NAME(_nc_setupscreen) (
     NCURSES_SP_NAME(_nc_init_acs) (NCURSES_SP_ARG);
 #if USE_WIDEC_SUPPORT
     sp->_screen_unicode = _nc_unicode_locale();
-    _nc_init_wacs();
+    if (_nc_wacs == 0) {
+       _nc_init_wacs();
+    }
     if (_nc_wacs == 0) {
        ReturnScreenError();
     }
@@ -618,10 +632,22 @@ NCURSES_SP_NAME(_nc_setupscreen) (
     NewScreen(sp)->_clear = TRUE;
     CurScreen(sp)->_clear = FALSE;
 
-    NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
-    NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
+    /*
+     * Get the current tty-modes. setupterm() may already have done this,
+     * unless we use the term-driver.
+     */
+#ifndef USE_TERM_DRIVER
+    if (cur_term != 0 &&
+       !memcmp(&cur_term->Ottyb, &null_TTY, sizeof(TTY)))
+#endif
+    {
+       NCURSES_SP_NAME(def_shell_mode) (NCURSES_SP_ARG);
+       NCURSES_SP_NAME(def_prog_mode) (NCURSES_SP_ARG);
+    }
 
     if (safe_ripoff_sp && safe_ripoff_sp != safe_ripoff_stack) {
+       ripoff_t *rop;
+
        for (rop = safe_ripoff_stack;
             rop != safe_ripoff_sp && (rop - safe_ripoff_stack) < N_RIPS;
             rop++) {
@@ -717,7 +743,7 @@ NCURSES_SP_NAME(_nc_ripoffline) (NCURSES_SP_DCLx
     int code = ERR;
 
     START_TRACE();
-    T((T_CALLED("ripoffline(%p,%d,%p)"), (void *) SP_PARM, line, init));
+    T((T_CALLED("ripoffline(%p,%d,%p)"), (void *) SP_PARM, line, TR_FUNC(init)));
 
 #if NCURSES_SP_FUNCS
     if (SP_PARM != 0 && SP_PARM->_prescreen)