Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 2 | * Copyright 2018-2020,2022 Thomas E. Dickey * |
| 3 | * Copyright 1998-2016,2017 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 4 | * * |
| 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: * |
| 12 | * * |
| 13 | * The above copyright notice and this permission notice shall be included * |
| 14 | * in all copies or substantial portions of the Software. * |
| 15 | * * |
| 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. * |
| 23 | * * |
| 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 * |
| 27 | * authorization. * |
| 28 | ****************************************************************************/ |
| 29 | |
| 30 | /**************************************************************************** |
| 31 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 32 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
| 33 | * and: Thomas E. Dickey 1996-on * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 34 | * and: Juergen Pfeifer 2009 * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 35 | ****************************************************************************/ |
| 36 | |
| 37 | /* |
| 38 | ** lib_newterm.c |
| 39 | ** |
| 40 | ** The newterm() function. |
| 41 | ** |
| 42 | */ |
| 43 | |
| 44 | #include <curses.priv.h> |
| 45 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 46 | #ifndef CUR |
| 47 | #define CUR SP_TERMTYPE |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 48 | #endif |
| 49 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 50 | #include <tic.h> |
| 51 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 52 | MODULE_ID("$Id: lib_newterm.c,v 1.104 2022/07/09 18:58:58 tom Exp $") |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 53 | |
| 54 | #ifdef USE_TERM_DRIVER |
| 55 | #define NumLabels InfoOf(SP_PARM).numlabels |
| 56 | #else |
| 57 | #define NumLabels num_labels |
| 58 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 59 | |
| 60 | #ifndef ONLCR /* Allows compilation under the QNX 4.2 OS */ |
| 61 | #define ONLCR 0 |
| 62 | #endif |
| 63 | |
| 64 | /* |
| 65 | * SVr4/XSI Curses specify that hardware echo is turned off in initscr, and not |
| 66 | * restored during the curses session. The library simulates echo in software. |
| 67 | * (The behavior is unspecified if the application enables hardware echo). |
| 68 | * |
| 69 | * The newterm function also initializes terminal settings, and since initscr |
| 70 | * is supposed to behave as if it calls newterm, we do it here. |
| 71 | */ |
| 72 | static NCURSES_INLINE int |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 73 | _nc_initscr(NCURSES_SP_DCL0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 74 | { |
| 75 | int result = ERR; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 76 | TERMINAL *term = TerminalOf(SP_PARM); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 77 | |
| 78 | /* for extended XPG4 conformance requires cbreak() at this point */ |
| 79 | /* (SVr4 curses does this anyway) */ |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 80 | T((T_CALLED("_nc_initscr(%p) ->term %p"), (void *) SP_PARM, (void *) term)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 81 | if (NCURSES_SP_NAME(cbreak) (NCURSES_SP_ARG) == OK) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 82 | TTY buf; |
| 83 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 84 | buf = term->Nttyb; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 85 | #ifdef TERMIOS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 86 | buf.c_lflag &= (unsigned) ~(ECHO | ECHONL); |
| 87 | buf.c_iflag &= (unsigned) ~(ICRNL | INLCR | IGNCR); |
| 88 | buf.c_oflag &= (unsigned) ~(ONLCR); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 89 | #elif HAVE_SGTTY_H |
| 90 | buf.sg_flags &= ~(ECHO | CRMOD); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 91 | #elif defined(EXP_WIN32_DRIVER) |
| 92 | buf.dwFlagIn = CONMODE_IN_DEFAULT; |
| 93 | buf.dwFlagOut = CONMODE_OUT_DEFAULT | VT_FLAG_OUT; |
| 94 | if (WINCONSOLE.isTermInfoConsole) { |
| 95 | buf.dwFlagIn |= VT_FLAG_IN; |
| 96 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 97 | #else |
| 98 | memset(&buf, 0, sizeof(buf)); |
| 99 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 100 | result = NCURSES_SP_NAME(_nc_set_tty_mode) (NCURSES_SP_ARGx &buf); |
| 101 | if (result == OK) |
| 102 | term->Nttyb = buf; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 103 | } |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 104 | returnCode(result); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | /* |
| 108 | * filter() has to be called before either initscr() or newterm(), so there is |
| 109 | * apparently no way to make this flag apply to some terminals and not others, |
| 110 | * aside from possibly delaying a filter() call until some terminals have been |
| 111 | * initialized. |
| 112 | */ |
| 113 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 114 | NCURSES_SP_NAME(filter) (NCURSES_SP_DCL0) |
| 115 | { |
| 116 | START_TRACE(); |
| 117 | T((T_CALLED("filter(%p)"), (void *) SP_PARM)); |
| 118 | #if NCURSES_SP_FUNCS |
| 119 | if (IsPreScreen(SP_PARM)) { |
| 120 | SP_PARM->_filtered = TRUE; |
| 121 | } |
| 122 | #else |
| 123 | _nc_prescreen.filter_mode = TRUE; |
| 124 | #endif |
| 125 | returnVoid; |
| 126 | } |
| 127 | |
| 128 | #if NCURSES_SP_FUNCS |
| 129 | NCURSES_EXPORT(void) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 130 | filter(void) |
| 131 | { |
| 132 | START_TRACE(); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 133 | T((T_CALLED("filter()"))); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 134 | _nc_prescreen.filter_mode = TRUE; |
| 135 | returnVoid; |
| 136 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 137 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 138 | |
| 139 | #if NCURSES_EXT_FUNCS |
| 140 | /* |
| 141 | * An extension, allowing the application to open a new screen without |
| 142 | * requiring it to also be filtered. |
| 143 | */ |
| 144 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 145 | NCURSES_SP_NAME(nofilter) (NCURSES_SP_DCL0) |
| 146 | { |
| 147 | START_TRACE(); |
| 148 | T((T_CALLED("nofilter(%p)"), (void *) SP_PARM)); |
| 149 | #if NCURSES_SP_FUNCS |
| 150 | if (IsPreScreen(SP_PARM)) { |
| 151 | SP_PARM->_filtered = FALSE; |
| 152 | } |
| 153 | #else |
| 154 | _nc_prescreen.filter_mode = FALSE; |
| 155 | #endif |
| 156 | returnVoid; |
| 157 | } |
| 158 | |
| 159 | #if NCURSES_SP_FUNCS |
| 160 | NCURSES_EXPORT(void) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 161 | nofilter(void) |
| 162 | { |
| 163 | START_TRACE(); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 164 | T((T_CALLED("nofilter()"))); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 165 | _nc_prescreen.filter_mode = FALSE; |
| 166 | returnVoid; |
| 167 | } |
| 168 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 169 | #endif /* NCURSES_EXT_FUNCS */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 170 | |
| 171 | NCURSES_EXPORT(SCREEN *) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 172 | NCURSES_SP_NAME(newterm) (NCURSES_SP_DCLx |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 173 | const char *name, |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 174 | FILE *ofp, |
| 175 | FILE *ifp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 176 | { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 177 | int errret; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 178 | SCREEN *result = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 179 | SCREEN *current; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 180 | TERMINAL *its_term; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 181 | FILE *_ofp = ofp ? ofp : stdout; |
| 182 | FILE *_ifp = ifp ? ifp : stdin; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 183 | TERMINAL *new_term = 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 184 | |
| 185 | START_TRACE(); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 186 | T((T_CALLED("newterm(%p, \"%s\", %p,%p)"), |
| 187 | (void *) SP_PARM, |
| 188 | (name ? name : ""), |
| 189 | (void *) ofp, |
| 190 | (void *) ifp)); |
| 191 | |
| 192 | #if NCURSES_SP_FUNCS |
| 193 | assert(SP_PARM != 0); |
| 194 | if (SP_PARM == 0) |
| 195 | returnSP(SP_PARM); |
| 196 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 197 | |
| 198 | _nc_init_pthreads(); |
| 199 | _nc_lock_global(curses); |
| 200 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 201 | current = CURRENT_SCREEN; |
| 202 | its_term = (current ? current->_term : 0); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 203 | |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 204 | #if defined(EXP_WIN32_DRIVER) |
| 205 | _setmode(fileno(_ifp), _O_BINARY); |
| 206 | _setmode(fileno(_ofp), _O_BINARY); |
| 207 | #endif |
| 208 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 209 | INIT_TERM_DRIVER(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 210 | /* this loads the capability entry, then sets LINES and COLS */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 211 | if ( |
| 212 | TINFO_SETUP_TERM(&new_term, name, |
| 213 | fileno(_ofp), &errret, FALSE) != ERR) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 214 | int slk_format; |
| 215 | int filter_mode; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 216 | |
| 217 | _nc_set_screen(0); |
| 218 | #ifdef USE_TERM_DRIVER |
| 219 | assert(new_term != 0); |
| 220 | #endif |
| 221 | |
| 222 | #if NCURSES_SP_FUNCS |
| 223 | slk_format = SP_PARM->slk_format; |
| 224 | filter_mode = SP_PARM->_filtered; |
| 225 | #else |
| 226 | slk_format = _nc_globals.slk_format; |
| 227 | filter_mode = _nc_prescreen.filter_mode; |
| 228 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 229 | |
| 230 | /* |
| 231 | * This actually allocates the screen structure, and saves the original |
| 232 | * terminal settings. |
| 233 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 234 | if (NCURSES_SP_NAME(_nc_setupscreen) ( |
| 235 | #if NCURSES_SP_FUNCS |
| 236 | &SP_PARM, |
| 237 | #endif |
| 238 | *(ptrLines(SP_PARM)), |
| 239 | *(ptrCols(SP_PARM)), |
| 240 | _ofp, |
| 241 | filter_mode, |
| 242 | slk_format) == ERR) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 243 | _nc_set_screen(current); |
| 244 | result = 0; |
| 245 | } else { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 246 | int value; |
| 247 | int cols; |
| 248 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 249 | #ifdef USE_TERM_DRIVER |
| 250 | TERMINAL_CONTROL_BLOCK *TCB; |
| 251 | #elif !NCURSES_SP_FUNCS |
| 252 | _nc_set_screen(CURRENT_SCREEN); |
| 253 | #endif |
| 254 | assert(SP_PARM != 0); |
| 255 | cols = *(ptrCols(SP_PARM)); |
| 256 | #ifdef USE_TERM_DRIVER |
| 257 | _nc_set_screen(SP_PARM); |
| 258 | TCB = (TERMINAL_CONTROL_BLOCK *) new_term; |
| 259 | TCB->csp = SP_PARM; |
| 260 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 261 | /* |
| 262 | * In setupterm() we did a set_curterm(), but it was before we set |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 263 | * CURRENT_SCREEN. So the "current" screen's terminal pointer was |
| 264 | * overwritten with a different terminal. Later, in |
| 265 | * _nc_setupscreen(), we set CURRENT_SCREEN and the terminal |
| 266 | * pointer in the new screen. |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 267 | * |
| 268 | * Restore the terminal-pointer for the pre-existing screen, if |
| 269 | * any. |
| 270 | */ |
| 271 | if (current) |
| 272 | current->_term = its_term; |
| 273 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 274 | #ifdef USE_TERM_DRIVER |
| 275 | SP_PARM->_term = new_term; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 276 | #else |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 277 | new_term = SP_PARM->_term; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 278 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 279 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 280 | /* allow user to set maximum escape delay from the environment */ |
| 281 | if ((value = _nc_getenv_num("ESCDELAY")) >= 0) { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 282 | #if NCURSES_EXT_FUNCS |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 283 | NCURSES_SP_NAME(set_escdelay) (NCURSES_SP_ARGx value); |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 284 | #else |
| 285 | ESCDELAY = value; |
| 286 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* if the terminal type has real soft labels, set those up */ |
| 290 | if (slk_format && NumLabels > 0 && SLK_STDFMT(slk_format)) |
| 291 | _nc_slk_initialize(StdScreen(SP_PARM), cols); |
| 292 | |
| 293 | SP_PARM->_ifd = fileno(_ifp); |
| 294 | NCURSES_SP_NAME(typeahead) (NCURSES_SP_ARGx fileno(_ifp)); |
| 295 | #ifdef TERMIOS |
| 296 | SP_PARM->_use_meta = ((new_term->Ottyb.c_cflag & CSIZE) == CS8 && |
| 297 | !(new_term->Ottyb.c_iflag & ISTRIP)) || |
| 298 | USE_KLIBC_KBD; |
| 299 | #else |
| 300 | SP_PARM->_use_meta = FALSE; |
| 301 | #endif |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 302 | SP_PARM->_endwin = ewInitial; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 303 | #ifndef USE_TERM_DRIVER |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 304 | /* |
| 305 | * Check whether we can optimize scrolling under dumb terminals in |
| 306 | * case we do not have any of these capabilities, scrolling |
| 307 | * optimization will be useless. |
| 308 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 309 | SP_PARM->_scrolling = ((scroll_forward && scroll_reverse) || |
| 310 | ((parm_rindex || |
| 311 | parm_insert_line || |
| 312 | insert_line) && |
| 313 | (parm_index || |
| 314 | parm_delete_line || |
| 315 | delete_line))); |
| 316 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 317 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 318 | NCURSES_SP_NAME(baudrate) (NCURSES_SP_ARG); /* sets a field in the screen structure */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 319 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 320 | SP_PARM->_keytry = 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 321 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 322 | /* compute movement costs so we can do better move optimization */ |
| 323 | #ifdef USE_TERM_DRIVER |
| 324 | TCBOf(SP_PARM)->drv->td_scinit(SP_PARM); |
| 325 | #else /* ! USE_TERM_DRIVER */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 326 | /* |
| 327 | * Check for mismatched graphic-rendition capabilities. Most SVr4 |
| 328 | * terminfo trees contain entries that have rmul or rmso equated to |
| 329 | * sgr0 (Solaris curses copes with those entries). We do this only |
| 330 | * for curses, since many termcap applications assume that |
| 331 | * smso/rmso and smul/rmul are paired, and will not function |
| 332 | * properly if we remove rmso or rmul. Curses applications |
| 333 | * shouldn't be looking at this detail. |
| 334 | */ |
| 335 | #define SGR0_TEST(mode) (mode != 0) && (exit_attribute_mode == 0 || strcmp(mode, exit_attribute_mode)) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 336 | SP_PARM->_use_rmso = SGR0_TEST(exit_standout_mode); |
| 337 | SP_PARM->_use_rmul = SGR0_TEST(exit_underline_mode); |
| 338 | #if USE_ITALIC |
| 339 | SP_PARM->_use_ritm = SGR0_TEST(exit_italics_mode); |
| 340 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 341 | |
| 342 | /* compute movement costs so we can do better move optimization */ |
| 343 | _nc_mvcur_init(); |
| 344 | |
| 345 | /* initialize terminal to a sane state */ |
| 346 | _nc_screen_init(); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 347 | #endif /* USE_TERM_DRIVER */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 348 | |
| 349 | /* Initialize the terminal line settings. */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 350 | _nc_initscr(NCURSES_SP_ARG); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 351 | |
| 352 | _nc_signal_handler(TRUE); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 353 | result = SP_PARM; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 354 | } |
| 355 | } |
| 356 | _nc_unlock_global(curses); |
| 357 | returnSP(result); |
| 358 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 359 | |
| 360 | #if NCURSES_SP_FUNCS |
| 361 | NCURSES_EXPORT(SCREEN *) |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 362 | newterm(const char *name, FILE *ofp, FILE *ifp) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 363 | { |
micky387 | 9b9f5e7 | 2025-07-08 18:04:53 -0400 | [diff] [blame] | 364 | SCREEN *rc; |
| 365 | |
| 366 | _nc_init_pthreads(); |
| 367 | _nc_lock_global(prescreen); |
| 368 | START_TRACE(); |
| 369 | rc = NCURSES_SP_NAME(newterm) (CURRENT_SCREEN_PRE, name, ofp, ifp); |
| 370 | _nc_forget_prescr(); |
| 371 | _nc_unlock_global(prescreen); |
| 372 | |
| 373 | return rc; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 374 | } |
| 375 | #endif |