1 /****************************************************************************
2 ,* Copyright 2020-2021,2022 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 */
42 #include <tic.h> /* VALID_STRING */
44 MODULE_ID("$Id: lib_cur_term.c,v 1.49 2022/05/28 17:56:55 tom Exp $")
47 #define CUR TerminalType(termp).
51 NCURSES_EXPORT(TERMINAL *)
52 NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_DCL0)
54 return ((0 != TerminalOf(SP_PARM)) ? TerminalOf(SP_PARM) : CurTerm);
59 NCURSES_EXPORT(TERMINAL *)
60 _nc_get_cur_term(void)
62 return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
66 NCURSES_EXPORT(TERMINAL *)
67 NCURSES_PUBLIC_VAR(cur_term) (void)
70 return NCURSES_SP_NAME(_nc_get_cur_term) (CURRENT_SCREEN);
72 return NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG);
77 NCURSES_EXPORT_VAR(TERMINAL *) cur_term = 0;
80 NCURSES_EXPORT(TERMINAL *)
81 NCURSES_SP_NAME(set_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
85 T((T_CALLED("set_curterm(%p)"), (void *) termp));
87 _nc_lock_global(curses);
90 SP_PARM->_term = termp;
97 #ifdef USE_TERM_DRIVER
98 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
99 ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
101 TCB->drv->isTerminfo &&
102 TerminalType(termp).Strings) {
103 PC = (char) (VALID_STRING(pad_char) ? pad_char[0] : 0);
107 ospeed = (NCURSES_OSPEED) _nc_ospeed(termp->_baudrate);
108 if (TerminalType(termp).Strings) {
109 PC = (char) (VALID_STRING(pad_char) ? pad_char[0] : 0);
116 _nc_unlock_global(curses);
118 T((T_RETURN("%p"), (void *) oldterm));
123 NCURSES_EXPORT(TERMINAL *)
124 set_curterm(TERMINAL *termp)
126 return NCURSES_SP_NAME(set_curterm) (CURRENT_SCREEN, termp);
131 NCURSES_SP_NAME(del_curterm) (NCURSES_SP_DCLx TERMINAL *termp)
135 T((T_CALLED("del_curterm(%p, %p)"), (void *) SP_PARM, (void *) termp));
138 #ifdef USE_TERM_DRIVER
139 TERMINAL_CONTROL_BLOCK *TCB = (TERMINAL_CONTROL_BLOCK *) termp;
143 NCURSES_SP_NAME(_nc_get_cur_term) (NCURSES_SP_ARG)
149 #if NCURSES_EXT_NUMBERS
150 #if NCURSES_EXT_COLORS
151 _nc_free_termtype1(&termp->type);
153 _nc_free_termtype2(&termp->type);
156 _nc_free_termtype2(&TerminalType(termp));
158 NCURSES_SP_NAME(set_curterm) (NCURSES_SP_ARGx 0);
160 FreeIfNeeded(termp->_termname);
161 #if USE_HOME_TERMINFO
162 if (_nc_globals.home_terminfo != 0) {
163 FreeAndNull(_nc_globals.home_terminfo);
166 #ifdef USE_TERM_DRIVER
168 TCB->drv->td_release(TCB);
171 /* discard memory used in tgetent's cache for this terminal */
172 _nc_tgetent_leak(termp);
174 if (--_nc_globals.terminal_count == 0) {
175 _nc_free_tparm(termp);
178 free(termp->tparm_state.fmt_buff);
179 free(termp->tparm_state.out_buff);
190 del_curterm(TERMINAL *termp)
194 _nc_lock_global(curses);
195 rc = NCURSES_SP_NAME(del_curterm) (CURRENT_SCREEN, termp);
196 _nc_unlock_global(curses);