1 /****************************************************************************
2 * Copyright 2020 Thomas E. Dickey *
3 * Copyright 1998-2016,2017 Free Software Foundation, Inc. *
5 * Permission is hereby granted, free of charge, to any person obtaining a *
6 * copy of this software and associated documentation files (the *
7 * "Software"), to deal in the Software without restriction, including *
8 * without limitation the rights to use, copy, modify, merge, publish, *
9 * distribute, distribute with modifications, sublicense, and/or sell *
10 * copies of the Software, and to permit persons to whom the Software is *
11 * furnished to do so, subject to the following conditions: *
13 * The above copyright notice and this permission notice shall be included *
14 * in all copies or substantial portions of the Software. *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
19 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
22 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * Except as contained in this notice, the name(s) of the above copyright *
25 * holders shall not be used in advertising or otherwise to promote the *
26 * sale, use or other dealings in this Software without prior written *
28 ****************************************************************************/
30 /****************************************************************************
31 * Author: Thomas E. Dickey <dickey@clark.net> 1997 *
32 ****************************************************************************/
34 * Module that "owns" the 'cur_term' variable:
36 * TERMINAL *set_curterm(TERMINAL *)
37 * int del_curterm(TERMINAL *)
40 #include <curses.priv.h>
41 #include <termcap.h> /* ospeed */
43 MODULE_ID("$Id: lib_cur_term.c,v 1.42 2020/02/02 23:34:34 tom Exp $")
46 #define CUR TerminalType(termp).
50 NCURSES_EXPORT(TERMINAL *)
51 NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_DCL0)
53 return ((0 != TerminalOf(SP_PARM)) ? TerminalOf(SP_PARM) : CurTerm);
58 NCURSES_EXPORT(TERMINAL *)
59 _nc_get_cur_term(void)
61 return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
65 NCURSES_EXPORT(TERMINAL *)
66 NCURSES_PUBLIC_VAR(cur_term) (void)
69 return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
71 return NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG);
76 NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0;
79 NCURSES_EXPORT(TERMINAL *)
80 NCURSES_SP_NAME(set_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
84 T((T_CALLED("set_curterm(%p)"), (void *) termp));
86 _nc_lock_global(curses);
89 SP_PARM->_term = termp;
96 #ifdef USE_TERM_DRIVER
97 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
98 ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
100 TCB->drv->isTerminfo &&
101 TerminalType(termp).Strings) {
102 PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
106 ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
107 if (TerminalType(termp).Strings) {
108 PC = (char) ((pad_char != NULL) ? pad_char[0] : 0);
115 _nc_unlock_global(curses);
117 T((T_RETURN("%p"), (void *) oldterm));
122 NCURSES_EXPORT(TERMINAL *)
123 set_curterm(TERMINAL *termp)
125 return NCURSES_SP_NAME(set_curterm) (CURRENT_SCREEN, termp);
130 NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
134 T((T_CALLED("del_curterm(%p, %p)"), (void *) SP_PARM, (void *) termp));
137 #ifdef USE_TERM_DRIVER
138 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
142 NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG)
148 #if NCURSES_EXT_NUMBERS
149 _nc_free_termtype(&termp->type);
151 _nc_free_termtype2(&TerminalType(termp));
153 NCURSES_SP_NAME(set_curterm) (NCURSES_SP_ARGx 0);
155 FreeIfNeeded(termp->_termname);
156 #if USE_HOME_TERMINFO
157 if (_nc_globals.home_terminfo != 0) {
158 FreeAndNull(_nc_globals.home_terminfo);
161 #ifdef USE_TERM_DRIVER
163 TCB->drv->td_release(TCB);
166 /* discard memory used in tgetent's cache for this terminal */
167 _nc_tgetent_leak(termp);
178 del_curterm(TERMINAL *termp)
182 _nc_lock_global(curses);
183 rc = NCURSES_SP_NAME(del_curterm) (CURRENT_SCREEN, termp);
184 _nc_unlock_global(curses);