Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 1 | /**************************************************************************** |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 2 | * Copyright (c) 1998-2014,2015 Free Software Foundation, Inc. * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 3 | * * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a * |
| 5 | * copy of this software and associated documentation files (the * |
| 6 | * "Software"), to deal in the Software without restriction, including * |
| 7 | * without limitation the rights to use, copy, modify, merge, publish, * |
| 8 | * distribute, distribute with modifications, sublicense, and/or sell * |
| 9 | * copies of the Software, and to permit persons to whom the Software is * |
| 10 | * furnished to do so, subject to the following conditions: * |
| 11 | * * |
| 12 | * The above copyright notice and this permission notice shall be included * |
| 13 | * in all copies or substantial portions of the Software. * |
| 14 | * * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * |
| 16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * |
| 17 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * |
| 18 | * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, * |
| 19 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR * |
| 20 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR * |
| 21 | * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * |
| 22 | * * |
| 23 | * Except as contained in this notice, the name(s) of the above copyright * |
| 24 | * holders shall not be used in advertising or otherwise to promote the * |
| 25 | * sale, use or other dealings in this Software without prior written * |
| 26 | * authorization. * |
| 27 | ****************************************************************************/ |
| 28 | |
| 29 | /**************************************************************************** |
| 30 | * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 * |
| 31 | * and: Eric S. Raymond <esr@snark.thyrsus.com> * |
| 32 | * and: Thomas E. Dickey 1996-on * |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 33 | * and: Juergen Pfeifer 2009 * |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 34 | ****************************************************************************/ |
| 35 | |
| 36 | /* |
| 37 | * Terminal setup routines common to termcap and terminfo: |
| 38 | * |
| 39 | * use_env(bool) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 40 | * use_tioctl(bool) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 41 | * setupterm(char *, int, int *) |
| 42 | */ |
| 43 | |
| 44 | #include <curses.priv.h> |
| 45 | #include <tic.h> /* for MAX_NAME_SIZE */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 46 | |
| 47 | #if HAVE_LOCALE_H |
| 48 | #include <locale.h> |
| 49 | #endif |
| 50 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 51 | MODULE_ID("$Id: lib_setup.c,v 1.164 2015/06/27 18:10:55 tom Exp $") |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 52 | |
| 53 | /**************************************************************************** |
| 54 | * |
| 55 | * Terminal size computation |
| 56 | * |
| 57 | ****************************************************************************/ |
| 58 | |
| 59 | #if HAVE_SIZECHANGE |
| 60 | # if !defined(sun) || !TERMIOS |
| 61 | # if HAVE_SYS_IOCTL_H |
| 62 | # include <sys/ioctl.h> |
| 63 | # endif |
| 64 | # endif |
| 65 | #endif |
| 66 | |
| 67 | #if NEED_PTEM_H |
| 68 | /* On SCO, they neglected to define struct winsize in termios.h -- it's only |
| 69 | * in termio.h and ptem.h (the former conflicts with other definitions). |
| 70 | */ |
| 71 | # include <sys/stream.h> |
| 72 | # include <sys/ptem.h> |
| 73 | #endif |
| 74 | |
| 75 | #if HAVE_LANGINFO_CODESET |
| 76 | #include <langinfo.h> |
| 77 | #endif |
| 78 | |
| 79 | /* |
| 80 | * SCO defines TIOCGSIZE and the corresponding struct. Other systems (SunOS, |
| 81 | * Solaris, IRIX) define TIOCGWINSZ and struct winsize. |
| 82 | */ |
| 83 | #ifdef TIOCGSIZE |
| 84 | # define IOCTL_WINSIZE TIOCGSIZE |
| 85 | # define STRUCT_WINSIZE struct ttysize |
| 86 | # define WINSIZE_ROWS(n) (int)n.ts_lines |
| 87 | # define WINSIZE_COLS(n) (int)n.ts_cols |
| 88 | #else |
| 89 | # ifdef TIOCGWINSZ |
| 90 | # define IOCTL_WINSIZE TIOCGWINSZ |
| 91 | # define STRUCT_WINSIZE struct winsize |
| 92 | # define WINSIZE_ROWS(n) (int)n.ws_row |
| 93 | # define WINSIZE_COLS(n) (int)n.ws_col |
| 94 | # endif |
| 95 | #endif |
| 96 | |
| 97 | /* |
| 98 | * Reduce explicit use of "cur_term" global variable. |
| 99 | */ |
| 100 | #undef CUR |
| 101 | #define CUR termp->type. |
| 102 | |
| 103 | /* |
| 104 | * Wrap global variables in this module. |
| 105 | */ |
| 106 | #if USE_REENTRANT |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 107 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 108 | NCURSES_EXPORT(char *) |
| 109 | NCURSES_PUBLIC_VAR(ttytype) (void) |
| 110 | { |
| 111 | static char empty[] = ""; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 112 | char *result = empty; |
| 113 | |
| 114 | #if NCURSES_SP_FUNCS |
| 115 | if (CURRENT_SCREEN) { |
| 116 | TERMINAL *termp = TerminalOf(CURRENT_SCREEN); |
| 117 | if (termp != 0) { |
| 118 | result = termp->type.term_names; |
| 119 | } |
| 120 | } |
| 121 | #else |
| 122 | if (cur_term != 0) { |
| 123 | result = cur_term->type.term_names; |
| 124 | } |
| 125 | #endif |
| 126 | return result; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 127 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 128 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 129 | NCURSES_EXPORT(int *) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 130 | _nc_ptr_Lines(SCREEN *sp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 131 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 132 | return ptrLines(sp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 133 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 134 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 135 | NCURSES_EXPORT(int) |
| 136 | NCURSES_PUBLIC_VAR(LINES) (void) |
| 137 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 138 | return *_nc_ptr_Lines(CURRENT_SCREEN); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 139 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 140 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 141 | NCURSES_EXPORT(int *) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 142 | _nc_ptr_Cols(SCREEN *sp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 143 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 144 | return ptrCols(sp); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 145 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 146 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 147 | NCURSES_EXPORT(int) |
| 148 | NCURSES_PUBLIC_VAR(COLS) (void) |
| 149 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 150 | return *_nc_ptr_Cols(CURRENT_SCREEN); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 151 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 152 | |
| 153 | NCURSES_EXPORT(int *) |
| 154 | _nc_ptr_Tabsize(SCREEN *sp) |
| 155 | { |
| 156 | return ptrTabsize(sp); |
| 157 | } |
| 158 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 159 | NCURSES_EXPORT(int) |
| 160 | NCURSES_PUBLIC_VAR(TABSIZE) (void) |
| 161 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 162 | return *_nc_ptr_Tabsize(CURRENT_SCREEN); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 163 | } |
| 164 | #else |
| 165 | NCURSES_EXPORT_VAR(char) ttytype[NAMESIZE] = ""; |
| 166 | NCURSES_EXPORT_VAR(int) LINES = 0; |
| 167 | NCURSES_EXPORT_VAR(int) COLS = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 168 | NCURSES_EXPORT_VAR(int) TABSIZE = 8; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 169 | #endif |
| 170 | |
| 171 | #if NCURSES_EXT_FUNCS |
| 172 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 173 | NCURSES_SP_NAME(set_tabsize) (NCURSES_SP_DCLx int value) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 174 | { |
| 175 | int code = OK; |
| 176 | #if USE_REENTRANT |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 177 | if (SP_PARM) { |
| 178 | SP_PARM->_TABSIZE = value; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 179 | } else { |
| 180 | code = ERR; |
| 181 | } |
| 182 | #else |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 183 | (void) SP_PARM; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 184 | TABSIZE = value; |
| 185 | #endif |
| 186 | return code; |
| 187 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 188 | |
| 189 | #if NCURSES_SP_FUNCS |
| 190 | NCURSES_EXPORT(int) |
| 191 | set_tabsize(int value) |
| 192 | { |
| 193 | return NCURSES_SP_NAME(set_tabsize) (CURRENT_SCREEN, value); |
| 194 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 195 | #endif |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 196 | #endif /* NCURSES_EXT_FUNCS */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 197 | |
| 198 | #if USE_SIGWINCH |
| 199 | /* |
| 200 | * If we have a pending SIGWINCH, set the flag in each screen. |
| 201 | */ |
| 202 | NCURSES_EXPORT(int) |
| 203 | _nc_handle_sigwinch(SCREEN *sp) |
| 204 | { |
| 205 | SCREEN *scan; |
| 206 | |
| 207 | if (_nc_globals.have_sigwinch) { |
| 208 | _nc_globals.have_sigwinch = 0; |
| 209 | |
| 210 | for (each_screen(scan)) { |
| 211 | scan->_sig_winch = TRUE; |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | return (sp ? sp->_sig_winch : 0); |
| 216 | } |
| 217 | |
| 218 | #endif |
| 219 | |
| 220 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 221 | NCURSES_SP_NAME(use_env) (NCURSES_SP_DCLx bool f) |
| 222 | { |
| 223 | T((T_CALLED("use_env(%p,%d)"), (void *) SP_PARM, (int) f)); |
| 224 | #if NCURSES_SP_FUNCS |
| 225 | START_TRACE(); |
| 226 | if (IsPreScreen(SP_PARM)) { |
| 227 | SP_PARM->_use_env = f; |
| 228 | } |
| 229 | #else |
| 230 | _nc_prescreen.use_env = f; |
| 231 | #endif |
| 232 | returnVoid; |
| 233 | } |
| 234 | |
| 235 | NCURSES_EXPORT(void) |
| 236 | NCURSES_SP_NAME(use_tioctl) (NCURSES_SP_DCLx bool f) |
| 237 | { |
| 238 | T((T_CALLED("use_tioctl(%p,%d)"), (void *) SP_PARM, (int) f)); |
| 239 | #if NCURSES_SP_FUNCS |
| 240 | START_TRACE(); |
| 241 | if (IsPreScreen(SP_PARM)) { |
| 242 | SP_PARM->_use_tioctl = f; |
| 243 | } |
| 244 | #else |
| 245 | _nc_prescreen.use_tioctl = f; |
| 246 | #endif |
| 247 | returnVoid; |
| 248 | } |
| 249 | |
| 250 | #if NCURSES_SP_FUNCS |
| 251 | NCURSES_EXPORT(void) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 252 | use_env(bool f) |
| 253 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 254 | T((T_CALLED("use_env(%d)"), (int) f)); |
| 255 | START_TRACE(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 256 | _nc_prescreen.use_env = f; |
| 257 | returnVoid; |
| 258 | } |
| 259 | |
| 260 | NCURSES_EXPORT(void) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 261 | use_tioctl(bool f) |
| 262 | { |
| 263 | T((T_CALLED("use_tioctl(%d)"), (int) f)); |
| 264 | START_TRACE(); |
| 265 | _nc_prescreen.use_tioctl = f; |
| 266 | returnVoid; |
| 267 | } |
| 268 | #endif |
| 269 | |
| 270 | NCURSES_EXPORT(void) |
| 271 | _nc_get_screensize(SCREEN *sp, |
| 272 | #ifdef USE_TERM_DRIVER |
| 273 | TERMINAL * termp, |
| 274 | #endif |
| 275 | int *linep, int *colp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 276 | /* Obtain lines/columns values from the environment and/or terminfo entry */ |
| 277 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 278 | #ifdef USE_TERM_DRIVER |
| 279 | TERMINAL_CONTROL_BLOCK *TCB; |
| 280 | int my_tabsize; |
| 281 | |
| 282 | assert(termp != 0 && linep != 0 && colp != 0); |
| 283 | TCB = (TERMINAL_CONTROL_BLOCK *) termp; |
| 284 | |
| 285 | my_tabsize = TCB->info.tabsize; |
| 286 | TCB->drv->td_size(TCB, linep, colp); |
| 287 | |
| 288 | #if USE_REENTRANT |
| 289 | if (sp != 0) { |
| 290 | sp->_TABSIZE = my_tabsize; |
| 291 | } |
| 292 | #else |
| 293 | (void) sp; |
| 294 | TABSIZE = my_tabsize; |
| 295 | #endif |
| 296 | T(("TABSIZE = %d", my_tabsize)); |
| 297 | #else /* !USE_TERM_DRIVER */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 298 | TERMINAL *termp = cur_term; |
| 299 | int my_tabsize; |
| 300 | |
| 301 | /* figure out the size of the screen */ |
| 302 | T(("screen size: terminfo lines = %d columns = %d", lines, columns)); |
| 303 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 304 | *linep = (int) lines; |
| 305 | *colp = (int) columns; |
| 306 | |
| 307 | if (_nc_prescreen.use_env || _nc_prescreen.use_tioctl) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 308 | int value; |
| 309 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 310 | #ifdef __EMX__ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 311 | { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 312 | int screendata[2]; |
| 313 | _scrsize(screendata); |
| 314 | *colp = screendata[0]; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 315 | *linep = ((sp != 0 && sp->_filtered) |
| 316 | ? 1 |
| 317 | : screendata[1]); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 318 | T(("EMX screen size: environment LINES = %d COLUMNS = %d", |
| 319 | *linep, *colp)); |
| 320 | } |
| 321 | #endif |
| 322 | #if HAVE_SIZECHANGE |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 323 | /* try asking the OS */ |
| 324 | if (NC_ISATTY(cur_term->Filedes)) { |
| 325 | STRUCT_WINSIZE size; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 326 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 327 | errno = 0; |
| 328 | do { |
| 329 | if (ioctl(cur_term->Filedes, IOCTL_WINSIZE, &size) >= 0) { |
| 330 | *linep = ((sp != 0 && sp->_filtered) |
| 331 | ? 1 |
| 332 | : WINSIZE_ROWS(size)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 333 | *colp = WINSIZE_COLS(size); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 334 | T(("SYS screen size: environment LINES = %d COLUMNS = %d", |
| 335 | *linep, *colp)); |
| 336 | break; |
| 337 | } |
| 338 | } while |
| 339 | (errno == EINTR); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 340 | } |
| 341 | #endif /* HAVE_SIZECHANGE */ |
| 342 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 343 | if (_nc_prescreen.use_env) { |
| 344 | if (_nc_prescreen.use_tioctl) { |
| 345 | /* |
| 346 | * If environment variables are used, update them. |
| 347 | */ |
| 348 | if ((sp == 0 || !sp->_filtered) && _nc_getenv_num("LINES") > 0) { |
| 349 | _nc_setenv_num("LINES", *linep); |
| 350 | } |
| 351 | if (_nc_getenv_num("COLUMNS") > 0) { |
| 352 | _nc_setenv_num("COLUMNS", *colp); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | /* |
| 357 | * Finally, look for environment variables. |
| 358 | * |
| 359 | * Solaris lets users override either dimension with an environment |
| 360 | * variable. |
| 361 | */ |
| 362 | if ((value = _nc_getenv_num("LINES")) > 0) { |
| 363 | *linep = value; |
| 364 | T(("screen size: environment LINES = %d", *linep)); |
| 365 | } |
| 366 | if ((value = _nc_getenv_num("COLUMNS")) > 0) { |
| 367 | *colp = value; |
| 368 | T(("screen size: environment COLUMNS = %d", *colp)); |
| 369 | } |
| 370 | } |
| 371 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 372 | /* if we can't get dynamic info about the size, use static */ |
| 373 | if (*linep <= 0) { |
| 374 | *linep = (int) lines; |
| 375 | } |
| 376 | if (*colp <= 0) { |
| 377 | *colp = (int) columns; |
| 378 | } |
| 379 | |
| 380 | /* the ultimate fallback, assume fixed 24x80 size */ |
| 381 | if (*linep <= 0) { |
| 382 | *linep = 24; |
| 383 | } |
| 384 | if (*colp <= 0) { |
| 385 | *colp = 80; |
| 386 | } |
| 387 | |
| 388 | /* |
| 389 | * Put the derived values back in the screen-size caps, so |
| 390 | * tigetnum() and tgetnum() will do the right thing. |
| 391 | */ |
| 392 | lines = (short) (*linep); |
| 393 | columns = (short) (*colp); |
| 394 | } |
| 395 | |
| 396 | T(("screen size is %dx%d", *linep, *colp)); |
| 397 | |
| 398 | if (VALID_NUMERIC(init_tabs)) |
| 399 | my_tabsize = (int) init_tabs; |
| 400 | else |
| 401 | my_tabsize = 8; |
| 402 | |
| 403 | #if USE_REENTRANT |
| 404 | if (sp != 0) |
| 405 | sp->_TABSIZE = my_tabsize; |
| 406 | #else |
| 407 | TABSIZE = my_tabsize; |
| 408 | #endif |
| 409 | T(("TABSIZE = %d", TABSIZE)); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 410 | #endif /* USE_TERM_DRIVER */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 411 | } |
| 412 | |
| 413 | #if USE_SIZECHANGE |
| 414 | NCURSES_EXPORT(void) |
| 415 | _nc_update_screensize(SCREEN *sp) |
| 416 | { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 417 | int new_lines; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 418 | int new_cols; |
| 419 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 420 | #ifdef USE_TERM_DRIVER |
| 421 | int old_lines; |
| 422 | int old_cols; |
| 423 | |
| 424 | assert(sp != 0); |
| 425 | |
| 426 | CallDriver_2(sp, td_getsize, &old_lines, &old_cols); |
| 427 | |
| 428 | #else |
| 429 | TERMINAL *termp = cur_term; |
| 430 | int old_lines = lines; |
| 431 | int old_cols = columns; |
| 432 | #endif |
| 433 | |
| 434 | TINFO_GET_SIZE(sp, sp->_term, &new_lines, &new_cols); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 435 | |
| 436 | /* |
| 437 | * See is_term_resized() and resizeterm(). |
| 438 | * We're doing it this way because those functions belong to the upper |
| 439 | * ncurses library, while this resides in the lower terminfo library. |
| 440 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 441 | if (sp != 0 && sp->_resize != 0) { |
| 442 | if ((new_lines != old_lines) || (new_cols != old_cols)) { |
| 443 | sp->_resize(NCURSES_SP_ARGx new_lines, new_cols); |
| 444 | } else if (sp->_sig_winch && (sp->_ungetch != 0)) { |
| 445 | sp->_ungetch(SP_PARM, KEY_RESIZE); /* so application can know this */ |
| 446 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 447 | sp->_sig_winch = FALSE; |
| 448 | } |
| 449 | } |
| 450 | #endif |
| 451 | |
| 452 | /**************************************************************************** |
| 453 | * |
| 454 | * Terminal setup |
| 455 | * |
| 456 | ****************************************************************************/ |
| 457 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 458 | #if NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 459 | /* |
| 460 | * Return 1 if entry found, 0 if not found, -1 if database not accessible, |
| 461 | * just like tgetent(). |
| 462 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 463 | int |
| 464 | _nc_setup_tinfo(const char *const tn, TERMTYPE *const tp) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 465 | { |
| 466 | char filename[PATH_MAX]; |
| 467 | int status = _nc_read_entry(tn, filename, tp); |
| 468 | |
| 469 | /* |
| 470 | * If we have an entry, force all of the cancelled strings to null |
| 471 | * pointers so we don't have to test them in the rest of the library. |
| 472 | * (The terminfo compiler bypasses this logic, since it must know if |
| 473 | * a string is cancelled, for merging entries). |
| 474 | */ |
| 475 | if (status == TGETENT_YES) { |
| 476 | unsigned n; |
| 477 | for_each_boolean(n, tp) { |
| 478 | if (!VALID_BOOLEAN(tp->Booleans[n])) |
| 479 | tp->Booleans[n] = FALSE; |
| 480 | } |
| 481 | for_each_string(n, tp) { |
| 482 | if (tp->Strings[n] == CANCELLED_STRING) |
| 483 | tp->Strings[n] = ABSENT_STRING; |
| 484 | } |
| 485 | } |
| 486 | return (status); |
| 487 | } |
| 488 | #endif |
| 489 | |
| 490 | /* |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 491 | ** Take the real command character out of the CC environment variable |
| 492 | ** and substitute it in for the prototype given in 'command_character'. |
| 493 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 494 | void |
| 495 | _nc_tinfo_cmdch(TERMINAL * termp, int proto) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 496 | { |
| 497 | unsigned i; |
| 498 | char CC; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 499 | char *tmp; |
| 500 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 501 | /* |
| 502 | * Only use the character if the string is a single character, |
| 503 | * since it is fairly common for developers to set the C compiler |
| 504 | * name as an environment variable - using the same symbol. |
| 505 | */ |
| 506 | if ((tmp = getenv("CC")) != 0 && strlen(tmp) == 1) { |
| 507 | CC = *tmp; |
| 508 | for_each_string(i, &(termp->type)) { |
| 509 | for (tmp = termp->type.Strings[i]; tmp && *tmp; tmp++) { |
| 510 | if (UChar(*tmp) == proto) |
| 511 | *tmp = CC; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 512 | } |
| 513 | } |
| 514 | } |
| 515 | } |
| 516 | |
| 517 | /* |
| 518 | * Find the locale which is in effect. |
| 519 | */ |
| 520 | NCURSES_EXPORT(char *) |
| 521 | _nc_get_locale(void) |
| 522 | { |
| 523 | char *env; |
| 524 | #if HAVE_LOCALE_H |
| 525 | /* |
| 526 | * This is preferable to using getenv() since it ensures that we are using |
| 527 | * the locale which was actually initialized by the application. |
| 528 | */ |
| 529 | env = setlocale(LC_CTYPE, 0); |
| 530 | #else |
| 531 | if (((env = getenv("LC_ALL")) != 0 && *env != '\0') |
| 532 | || ((env = getenv("LC_CTYPE")) != 0 && *env != '\0') |
| 533 | || ((env = getenv("LANG")) != 0 && *env != '\0')) { |
| 534 | ; |
| 535 | } |
| 536 | #endif |
| 537 | T(("_nc_get_locale %s", _nc_visbuf(env))); |
| 538 | return env; |
| 539 | } |
| 540 | |
| 541 | /* |
| 542 | * Check if we are running in a UTF-8 locale. |
| 543 | */ |
| 544 | NCURSES_EXPORT(int) |
| 545 | _nc_unicode_locale(void) |
| 546 | { |
| 547 | int result = 0; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 548 | #if defined(__MINGW32__) && USE_WIDEC_SUPPORT |
| 549 | result = 1; |
| 550 | #elif HAVE_LANGINFO_CODESET |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 551 | char *env = nl_langinfo(CODESET); |
| 552 | result = !strcmp(env, "UTF-8"); |
| 553 | T(("_nc_unicode_locale(%s) ->%d", env, result)); |
| 554 | #else |
| 555 | char *env = _nc_get_locale(); |
| 556 | if (env != 0) { |
| 557 | if (strstr(env, ".UTF-8") != 0) { |
| 558 | result = 1; |
| 559 | T(("_nc_unicode_locale(%s) ->%d", env, result)); |
| 560 | } |
| 561 | } |
| 562 | #endif |
| 563 | return result; |
| 564 | } |
| 565 | |
| 566 | #define CONTROL_N(s) ((s) != 0 && strstr(s, "\016") != 0) |
| 567 | #define CONTROL_O(s) ((s) != 0 && strstr(s, "\017") != 0) |
| 568 | |
| 569 | /* |
| 570 | * Check for known broken cases where a UTF-8 locale breaks the alternate |
| 571 | * character set. |
| 572 | */ |
| 573 | NCURSES_EXPORT(int) |
| 574 | _nc_locale_breaks_acs(TERMINAL * termp) |
| 575 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 576 | const char *env_name = "NCURSES_NO_UTF8_ACS"; |
| 577 | const char *env; |
| 578 | int value; |
| 579 | int result = 0; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 580 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 581 | T((T_CALLED("_nc_locale_breaks_acs:%d"), result)); |
| 582 | if (getenv(env_name) != 0) { |
| 583 | result = _nc_getenv_num(env_name); |
| 584 | } else if ((value = tigetnum("U8")) >= 0) { |
| 585 | result = value; /* use extension feature */ |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 586 | } else if ((env = getenv("TERM")) != 0) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 587 | if (strstr(env, "linux")) { |
| 588 | result = 1; /* always broken */ |
| 589 | } else if (strstr(env, "screen") != 0 |
| 590 | && ((env = getenv("TERMCAP")) != 0 |
| 591 | && strstr(env, "screen") != 0) |
| 592 | && strstr(env, "hhII00") != 0) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 593 | if (CONTROL_N(enter_alt_charset_mode) || |
| 594 | CONTROL_O(enter_alt_charset_mode) || |
| 595 | CONTROL_N(set_attributes) || |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 596 | CONTROL_O(set_attributes)) { |
| 597 | result = 1; |
| 598 | } |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 599 | } |
| 600 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 601 | returnCode(result); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 602 | } |
| 603 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 604 | NCURSES_EXPORT(int) |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 605 | TINFO_SETUP_TERM(TERMINAL ** tp, |
| 606 | NCURSES_CONST char *tname, |
| 607 | int Filedes, |
| 608 | int *errret, |
| 609 | int reuse) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 610 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 611 | #ifdef USE_TERM_DRIVER |
| 612 | TERMINAL_CONTROL_BLOCK *TCB = 0; |
| 613 | #else |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 614 | int status; |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 615 | #endif |
| 616 | TERMINAL *termp; |
| 617 | SCREEN *sp = 0; |
| 618 | int code = ERR; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 619 | |
| 620 | START_TRACE(); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 621 | |
| 622 | #ifdef USE_TERM_DRIVER |
| 623 | T((T_CALLED("_nc_setupterm_ex(%p,%s,%d,%p)"), |
| 624 | (void *) tp, _nc_visbuf(tname), Filedes, (void *) errret)); |
| 625 | |
| 626 | if (tp == 0) { |
| 627 | ret_error0(TGETENT_ERR, |
| 628 | "Invalid parameter, internal error.\n"); |
| 629 | } else |
| 630 | termp = *tp; |
| 631 | #else |
| 632 | termp = cur_term; |
| 633 | T((T_CALLED("setupterm(%s,%d,%p)"), _nc_visbuf(tname), Filedes, (void *) errret)); |
| 634 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 635 | |
| 636 | if (tname == 0) { |
| 637 | tname = getenv("TERM"); |
| 638 | if (tname == 0 || *tname == '\0') { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 639 | #ifdef USE_TERM_DRIVER |
| 640 | tname = "unknown"; |
| 641 | #else |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 642 | ret_error0(TGETENT_ERR, "TERM environment variable not set.\n"); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 643 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | |
| 647 | if (strlen(tname) > MAX_NAME_SIZE) { |
| 648 | ret_error(TGETENT_ERR, |
| 649 | "TERM environment must be <= %d characters.\n", |
| 650 | MAX_NAME_SIZE); |
| 651 | } |
| 652 | |
| 653 | T(("your terminal name is %s", tname)); |
| 654 | |
| 655 | /* |
| 656 | * Allow output redirection. This is what SVr3 does. If stdout is |
| 657 | * directed to a file, screen updates go to standard error. |
| 658 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 659 | if (Filedes == STDOUT_FILENO && !NC_ISATTY(Filedes)) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 660 | Filedes = STDERR_FILENO; |
| 661 | |
| 662 | /* |
| 663 | * Check if we have already initialized to use this terminal. If so, we |
| 664 | * do not need to re-read the terminfo entry, or obtain TTY settings. |
| 665 | * |
| 666 | * This is an improvement on SVr4 curses. If an application mixes curses |
| 667 | * and termcap calls, it may call both initscr and tgetent. This is not |
| 668 | * really a good thing to do, but can happen if someone tries using ncurses |
| 669 | * with the readline library. The problem we are fixing is that when |
| 670 | * tgetent calls setupterm, the resulting Ottyb struct in cur_term is |
| 671 | * zeroed. A subsequent call to endwin uses the zeroed terminal settings |
| 672 | * rather than the ones saved in initscr. So we check if cur_term appears |
| 673 | * to contain terminal settings for the same output file as our current |
| 674 | * call - and copy those terminal settings. (SVr4 curses does not do this, |
| 675 | * however applications that are working around the problem will still work |
| 676 | * properly with this feature). |
| 677 | */ |
| 678 | if (reuse |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 679 | && (termp != 0) |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 680 | && termp->Filedes == Filedes |
| 681 | && termp->_termname != 0 |
| 682 | && !strcmp(termp->_termname, tname) |
| 683 | && _nc_name_match(termp->type.term_names, tname, "|")) { |
| 684 | T(("reusing existing terminal information and mode-settings")); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 685 | code = OK; |
| 686 | #ifdef USE_TERM_DRIVER |
| 687 | TCB = (TERMINAL_CONTROL_BLOCK *) termp; |
| 688 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 689 | } else { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 690 | #ifdef USE_TERM_DRIVER |
| 691 | TERMINAL_CONTROL_BLOCK *my_tcb; |
| 692 | my_tcb = typeCalloc(TERMINAL_CONTROL_BLOCK, 1); |
| 693 | termp = &(my_tcb->term); |
| 694 | #else |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 695 | termp = typeCalloc(TERMINAL, 1); |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 696 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 697 | if (termp == 0) { |
| 698 | ret_error0(TGETENT_ERR, |
| 699 | "Not enough memory to create terminal structure.\n"); |
| 700 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 701 | #ifdef USE_TERM_DRIVER |
| 702 | INIT_TERM_DRIVER(); |
| 703 | TCB = (TERMINAL_CONTROL_BLOCK *) termp; |
| 704 | code = _nc_globals.term_driver(TCB, tname, errret); |
| 705 | if (code == OK) { |
| 706 | termp->Filedes = (short) Filedes; |
| 707 | termp->_termname = strdup(tname); |
| 708 | } else { |
| 709 | ret_error0(errret ? *errret : TGETENT_ERR, |
| 710 | "Could not find any driver to handle this terminal.\n"); |
| 711 | } |
| 712 | #else |
| 713 | #if NCURSES_USE_DATABASE || NCURSES_USE_TERMCAP |
| 714 | status = _nc_setup_tinfo(tname, &termp->type); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 715 | #else |
| 716 | status = TGETENT_NO; |
| 717 | #endif |
| 718 | |
| 719 | /* try fallback list if entry on disk */ |
| 720 | if (status != TGETENT_YES) { |
| 721 | const TERMTYPE *fallback = _nc_fallback(tname); |
| 722 | |
| 723 | if (fallback) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 724 | _nc_copy_termtype(&(termp->type), fallback); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 725 | status = TGETENT_YES; |
| 726 | } |
| 727 | } |
| 728 | |
| 729 | if (status != TGETENT_YES) { |
| 730 | del_curterm(termp); |
| 731 | if (status == TGETENT_ERR) { |
| 732 | ret_error0(status, "terminals database is inaccessible\n"); |
| 733 | } else if (status == TGETENT_NO) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 734 | ret_error1(status, "unknown terminal type.\n", tname); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 735 | } |
| 736 | } |
| 737 | #if !USE_REENTRANT |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 738 | strncpy(ttytype, termp->type.term_names, (size_t) (NAMESIZE - 1)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 739 | ttytype[NAMESIZE - 1] = '\0'; |
| 740 | #endif |
| 741 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 742 | termp->Filedes = (short) Filedes; |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 743 | termp->_termname = strdup(tname); |
| 744 | |
| 745 | set_curterm(termp); |
| 746 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 747 | if (command_character) |
| 748 | _nc_tinfo_cmdch(termp, UChar(*command_character)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 749 | |
| 750 | /* |
| 751 | * If an application calls setupterm() rather than initscr() or |
| 752 | * newterm(), we will not have the def_prog_mode() call in |
| 753 | * _nc_setupscreen(). Do it now anyway, so we can initialize the |
| 754 | * baudrate. |
| 755 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 756 | if (NC_ISATTY(Filedes)) { |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 757 | def_prog_mode(); |
| 758 | baudrate(); |
| 759 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 760 | code = OK; |
| 761 | #endif |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 762 | } |
| 763 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 764 | #ifdef USE_TERM_DRIVER |
| 765 | *tp = termp; |
| 766 | NCURSES_SP_NAME(set_curterm) (sp, termp); |
| 767 | TCB->drv->td_init(TCB); |
| 768 | #else |
| 769 | sp = SP; |
| 770 | #endif |
| 771 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 772 | /* |
| 773 | * We should always check the screensize, just in case. |
| 774 | */ |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 775 | TINFO_GET_SIZE(sp, termp, ptrLines(sp), ptrCols(sp)); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 776 | |
| 777 | if (errret) |
| 778 | *errret = TGETENT_YES; |
| 779 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 780 | #ifndef USE_TERM_DRIVER |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 781 | if (generic_type) { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 782 | /* |
| 783 | * BSD 4.3's termcap contains mis-typed "gn" for wy99. Do a sanity |
| 784 | * check before giving up. |
| 785 | */ |
| 786 | if ((VALID_STRING(cursor_address) |
| 787 | || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home))) |
| 788 | && VALID_STRING(clear_screen)) { |
| 789 | ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname); |
| 790 | } else { |
| 791 | del_curterm(termp); |
| 792 | ret_error1(TGETENT_NO, "I need something more specific.\n", tname); |
| 793 | } |
| 794 | } else if (hard_copy) { |
| 795 | ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 796 | } |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 797 | #endif |
| 798 | returnCode(code); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 799 | } |
| 800 | |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 801 | #if NCURSES_SP_FUNCS |
| 802 | /* |
| 803 | * In case of handling multiple screens, we need to have a screen before |
| 804 | * initialization in setupscreen takes place. This is to extend the substitute |
| 805 | * for some of the stuff in _nc_prescreen, especially for slk and ripoff |
| 806 | * handling which should be done per screen. |
| 807 | */ |
| 808 | NCURSES_EXPORT(SCREEN *) |
| 809 | new_prescr(void) |
| 810 | { |
| 811 | static SCREEN *sp; |
| 812 | |
| 813 | START_TRACE(); |
| 814 | T((T_CALLED("new_prescr()"))); |
| 815 | |
| 816 | if (sp == 0) { |
| 817 | sp = _nc_alloc_screen_sp(); |
| 818 | if (sp != 0) { |
| 819 | sp->rsp = sp->rippedoff; |
| 820 | sp->_filtered = _nc_prescreen.filter_mode; |
| 821 | sp->_use_env = _nc_prescreen.use_env; |
| 822 | #if NCURSES_NO_PADDING |
| 823 | sp->_no_padding = _nc_prescreen._no_padding; |
| 824 | #endif |
| 825 | sp->slk_format = 0; |
| 826 | sp->_slk = 0; |
| 827 | sp->_prescreen = TRUE; |
| 828 | SP_PRE_INIT(sp); |
| 829 | #if USE_REENTRANT |
| 830 | sp->_TABSIZE = _nc_prescreen._TABSIZE; |
| 831 | sp->_ESCDELAY = _nc_prescreen._ESCDELAY; |
| 832 | #endif |
| 833 | } |
| 834 | } |
| 835 | returnSP(sp); |
| 836 | } |
| 837 | #endif |
| 838 | |
| 839 | #ifdef USE_TERM_DRIVER |
| 840 | /* |
| 841 | * This entrypoint is called from tgetent() to allow a special case of reusing |
| 842 | * the same TERMINAL data (see comment). |
| 843 | */ |
| 844 | NCURSES_EXPORT(int) |
| 845 | _nc_setupterm(NCURSES_CONST char *tname, |
| 846 | int Filedes, |
| 847 | int *errret, |
| 848 | int reuse) |
| 849 | { |
| 850 | int res; |
| 851 | TERMINAL *termp = 0; |
| 852 | res = TINFO_SETUP_TERM(&termp, tname, Filedes, errret, reuse); |
| 853 | if (ERR != res) |
| 854 | NCURSES_SP_NAME(set_curterm) (CURRENT_SCREEN_PRE, termp); |
| 855 | return res; |
| 856 | } |
| 857 | #endif |
| 858 | |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 859 | /* |
| 860 | * setupterm(termname, Filedes, errret) |
| 861 | * |
| 862 | * Find and read the appropriate object file for the terminal |
| 863 | * Make cur_term point to the structure. |
| 864 | */ |
| 865 | NCURSES_EXPORT(int) |
| 866 | setupterm(NCURSES_CONST char *tname, int Filedes, int *errret) |
| 867 | { |
Steve Kondik | ae271bc | 2015-11-15 02:50:53 +0100 | [diff] [blame] | 868 | START_TRACE(); |
Amit Daniel Kachhap | e6a01f5 | 2011-07-20 11:45:59 +0530 | [diff] [blame] | 869 | return _nc_setupterm(tname, Filedes, errret, FALSE); |
| 870 | } |