Bug Summary

File:src/lib/libcurses/base/lib_set_term.c
Warning:line 111, column 3
Value stored to 'last' is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.0 -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name lib_set_term.c -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 1 -fhalf-no-semantic-interposition -mframe-pointer=all -relaxed-aliasing -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/lib/libcurses/obj -resource-dir /usr/local/lib/clang/13.0.0 -I . -I /usr/src/lib/libcurses -D PIC -internal-isystem /usr/local/lib/clang/13.0.0/include -internal-externc-isystem /usr/include -O2 -fdebug-compilation-dir=/usr/src/lib/libcurses/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /home/ben/Projects/vmm/scan-build/2022-01-12-194120-40624-1 -x c /usr/src/lib/libcurses/base/lib_set_term.c
1/* $OpenBSD: lib_set_term.c,v 1.14 2021/03/10 20:16:08 millert Exp $ */
2
3/****************************************************************************
4 * Copyright (c) 1998-2007,2008 Free Software Foundation, Inc. *
5 * *
6 * Permission is hereby granted, free of charge, to any person obtaining a *
7 * copy of this software and associated documentation files (the *
8 * "Software"), to deal in the Software without restriction, including *
9 * without limitation the rights to use, copy, modify, merge, publish, *
10 * distribute, distribute with modifications, sublicense, and/or sell *
11 * copies of the Software, and to permit persons to whom the Software is *
12 * furnished to do so, subject to the following conditions: *
13 * *
14 * The above copyright notice and this permission notice shall be included *
15 * in all copies or substantial portions of the Software. *
16 * *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS *
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF *
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. *
20 * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
21 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
22 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR *
23 * THE USE OR OTHER DEALINGS IN THE SOFTWARE. *
24 * *
25 * Except as contained in this notice, the name(s) of the above copyright *
26 * holders shall not be used in advertising or otherwise to promote the *
27 * sale, use or other dealings in this Software without prior written *
28 * authorization. *
29 ****************************************************************************/
30
31/****************************************************************************
32 * Author: Zeyd M. Ben-Halim <zmbenhal@netcom.com> 1992,1995 *
33 * and: Eric S. Raymond <esr@snark.thyrsus.com> *
34 * and: Thomas E. Dickey 1996-on *
35 ****************************************************************************/
36
37/*
38** lib_set_term.c
39**
40** The routine set_term().
41**
42*/
43
44#include <curses.priv.h>
45
46#include <term.h> /* cur_term */
47#include <tic.h>
48
49MODULE_ID("$Id: lib_set_term.c,v 1.14 2021/03/10 20:16:08 millert Exp $")
50
51NCURSES_EXPORT(SCREEN *)SCREEN *
52set_term(SCREEN *screenp)
53{
54 SCREEN *oldSP;
55 SCREEN *newSP;
56
57 T((T_CALLED("set_term(%p)"), screenp));
58
59 _nc_lock_global(curses);
60
61 oldSP = SP;
62 _nc_set_screen(screenp)SP = screenp;
63 newSP = SP;
64
65 if (newSP != 0) {
66 set_curterm(newSP->_term);
67#if !USE_REENTRANT0
68 curscr = newSP->_curscr;
69 newscr = newSP->_newscr;
70 stdscr = newSP->_stdscr;
71 COLORS = newSP->_color_count;
72 COLOR_PAIRS = newSP->_pair_count;
73#endif
74 } else {
75 set_curterm(0);
76#if !USE_REENTRANT0
77 curscr = 0;
78 newscr = 0;
79 stdscr = 0;
80 COLORS = 0;
81 COLOR_PAIRS = 0;
82#endif
83 }
84
85 _nc_unlock_global(curses);
86
87 T((T_RETURN("%p"), oldSP));
88 return (oldSP);
89}
90
91static void
92_nc_free_keytry(TRIES * kt)
93{
94 if (kt != 0) {
95 _nc_free_keytry(kt->child);
96 _nc_free_keytry(kt->sibling);
97 free(kt);
98 }
99}
100
101static bool_Bool
102delink_screen(SCREEN *sp)
103{
104 SCREEN *last = 0;
105 SCREEN *temp;
106 bool_Bool result = FALSE0;
107
108 for (each_screen(temp)temp = _nc_screen_chain; temp != 0; temp = (temp)->_next_screen) {
109 if (temp == sp) {
110 if (last)
111 last = sp->_next_screen;
Value stored to 'last' is never read
112 else
113 _nc_screen_chain = sp->_next_screen;
114 result = TRUE1;
115 break;
116 }
117 last = temp;
118 }
119 return result;
120}
121
122/*
123 * Free the storage associated with the given SCREEN sp.
124 */
125NCURSES_EXPORT(void)void
126delscreen(SCREEN *sp)
127{
128 int i;
129
130 T((T_CALLED("delscreen(%p)"), sp));
131
132 _nc_lock_global(curses);
133 if (delink_screen(sp)) {
134
135 (void) _nc_freewin(sp->_curscr);
136 (void) _nc_freewin(sp->_newscr);
137 (void) _nc_freewin(sp->_stdscr);
138
139 if (sp->_slk != 0) {
140 if (sp->_slk->ent != 0) {
141 for (i = 0; i < sp->_slk->labcnt; ++i) {
142 FreeIfNeeded(sp->_slk->ent[i].ent_text)if ((sp->_slk->ent[i].ent_text) != 0) free(sp->_slk->
ent[i].ent_text)
;
143 FreeIfNeeded(sp->_slk->ent[i].form_text)if ((sp->_slk->ent[i].form_text) != 0) free(sp->_slk
->ent[i].form_text)
;
144 }
145 free(sp->_slk->ent);
146 }
147 free(sp->_slk);
148 sp->_slk = 0;
149 }
150
151 _nc_free_keytry(sp->_keytry);
152 sp->_keytry = 0;
153
154 _nc_free_keytry(sp->_key_ok);
155 sp->_key_ok = 0;
156
157 FreeIfNeeded(sp->_current_attr)if ((sp->_current_attr) != 0) free(sp->_current_attr);
158
159 FreeIfNeeded(sp->_color_table)if ((sp->_color_table) != 0) free(sp->_color_table);
160 FreeIfNeeded(sp->_color_pairs)if ((sp->_color_pairs) != 0) free(sp->_color_pairs);
161
162 FreeIfNeeded(sp->oldhash)if ((sp->oldhash) != 0) free(sp->oldhash);
163 FreeIfNeeded(sp->newhash)if ((sp->newhash) != 0) free(sp->newhash);
164 FreeIfNeeded(sp->hashtab)if ((sp->hashtab) != 0) free(sp->hashtab);
165
166 FreeIfNeeded(sp->_acs_map)if ((sp->_acs_map) != 0) free(sp->_acs_map);
167 FreeIfNeeded(sp->_screen_acs_map)if ((sp->_screen_acs_map) != 0) free(sp->_screen_acs_map
)
;
168
169 /*
170 * If the associated output stream has been closed, we can discard the
171 * set-buffer. Limit the error check to EBADF, since fflush may fail
172 * for other reasons than trying to operate upon a closed stream.
173 */
174 if (sp->_ofp != 0
175 && sp->_setbuf != 0
176 && fflush(sp->_ofp) != 0
177 && errno(*__errno()) == EBADF9) {
178 free(sp->_setbuf);
179 }
180
181 del_curterm(sp->_term);
182 free(sp);
183
184 /*
185 * If this was the current screen, reset everything that the
186 * application might try to use (except cur_term, which may have
187 * multiple references in different screens).
188 */
189 if (sp == SP) {
190#if !USE_REENTRANT0
191 curscr = 0;
192 newscr = 0;
193 stdscr = 0;
194 COLORS = 0;
195 COLOR_PAIRS = 0;
196#endif
197 _nc_set_screen(0)SP = 0;
198 }
199 }
200 _nc_unlock_global(curses);
201
202 returnVoidreturn;
203}
204
205static bool_Bool
206no_mouse_event(SCREEN *sp GCC_UNUSED__attribute__((__unused__)))
207{
208 return FALSE0;
209}
210
211static bool_Bool
212no_mouse_inline(SCREEN *sp GCC_UNUSED__attribute__((__unused__)))
213{
214 return FALSE0;
215}
216
217static bool_Bool
218no_mouse_parse(SCREEN *sp GCC_UNUSED__attribute__((__unused__)), int code GCC_UNUSED__attribute__((__unused__)))
219{
220 return TRUE1;
221}
222
223static void
224no_mouse_resume(SCREEN *sp GCC_UNUSED__attribute__((__unused__)))
225{
226}
227
228static void
229no_mouse_wrap(SCREEN *sp GCC_UNUSED__attribute__((__unused__)))
230{
231}
232
233#if NCURSES_EXT_FUNCS20081102 && USE_COLORFGBG0
234static char *
235extract_fgbg(char *src, int *result)
236{
237 char *dst = 0;
238 long value = strtol(src, &dst, 0);
239
240 if (dst == 0) {
241 dst = src;
242 } else if (value >= 0) {
243 *result = value;
244 }
245 while (*dst != 0 && *dst != ';')
246 dst++;
247 if (*dst == ';')
248 dst++;
249 return dst;
250}
251#endif
252
253/* OS-independent screen initializations */
254NCURSES_EXPORT(int)int
255_nc_setupscreen(int slines GCC_UNUSED__attribute__((__unused__)),
256 int scolumns GCC_UNUSED__attribute__((__unused__)),
257 FILE *output,
258 bool_Bool filtered,
259 int slk_format)
260{
261 char *env;
262 int bottom_stolen = 0;
263 bool_Bool support_cookies = USE_XMC_SUPPORT0;
264 ripoff_t *rop;
265
266 T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
267 slines, scolumns, output, filtered, slk_format));
268
269 assert(SP == 0)((void)0); /* has been reset in newterm() ! */
270 if (!_nc_alloc_screen()((SP = (SCREEN *)calloc((1),sizeof(SCREEN))) != 0)
271 || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)(chtype *)calloc((128),sizeof(chtype))) == 0)
272 || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)(_Bool *)calloc((128),sizeof(_Bool))) == 0)) {
273 returnCode(ERR)return (-1);
274 }
275
276 T(("created SP %p", SP));
277 SP->_next_screen = _nc_screen_chain;
278 _nc_screen_chain = SP;
279
280 if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)(cchar_t *)calloc((1),sizeof(cchar_t))) == 0)
281 returnCode(ERR)return (-1);
282
283 /*
284 * We should always check the screensize, just in case.
285 */
286 _nc_get_screensize(SP, &slines, &scolumns);
287 SET_LINES(slines)LINES = slines;
288 SET_COLS(scolumns)COLS = scolumns;
289 T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
290
291 SP->_filtered = filtered;
292
293 /* implement filter mode */
294 if (filtered) {
295 slines = 1;
296 SET_LINES(slines)LINES = slines;
297 clear_screencur_term->type. Strings[5] = 0;
298 cursor_downcur_term->type. Strings[11] = parm_down_cursorcur_term->type. Strings[107] = 0;
299 cursor_addresscur_term->type. Strings[10] = 0;
300 cursor_upcur_term->type. Strings[19] = parm_up_cursorcur_term->type. Strings[114] = 0;
301 row_addresscur_term->type. Strings[127] = 0;
302
303 cursor_homecur_term->type. Strings[12] = carriage_returncur_term->type. Strings[2];
304 T(("filter screensize %dx%d", LINES, COLS));
305 }
306#ifdef __DJGPP__
307 T(("setting output mode to binary"));
308 fflush(output);
309 setmode(output, O_BINARY0);
310#endif
311 _nc_set_buffer(output, TRUE1);
312 SP->_term = cur_term;
313 SP->_lines = slines;
314 SP->_lines_avail = slines;
315 SP->_columns = scolumns;
316 SP->_cursrow = -1;
317 SP->_curscol = -1;
318 SP->_nl = TRUE1;
319 SP->_raw = FALSE0;
320 SP->_cbreak = 0;
321 SP->_echo = TRUE1;
322 SP->_fifohead = -1;
323 SP->_endwin = TRUE1;
324 SP->_ofp = output;
325 SP->_cursor = -1; /* cannot know real cursor shape */
326
327 SetNoPadding(SP)_nc_set_no_padding(SP);
328
329#if NCURSES_EXT_FUNCS20081102
330 SP->_default_color = FALSE0;
331 SP->_has_sgr_39_49 = FALSE0;
332
333 /*
334 * Set our assumption of the terminal's default foreground and background
335 * colors. The curs_color man-page states that we can assume that the
336 * background is black. The origin of this assumption appears to be
337 * terminals that displayed colored text, but no colored backgrounds, e.g.,
338 * the first colored terminals around 1980. More recent ones with better
339 * technology can display not only colored backgrounds, but all
340 * combinations. So a terminal might be something other than "white" on
341 * black (green/black looks monochrome too), but black on white or even
342 * on ivory.
343 *
344 * White-on-black is the simplest thing to use for monochrome. Almost
345 * all applications that use color paint both text and background, so
346 * the distinction is moot. But a few do not - which is why we leave this
347 * configurable (a better solution is to use assume_default_colors() for
348 * the rare applications that do require that sort of appearance, since
349 * is appears that more users expect to be able to make a white-on-black
350 * or black-on-white display under control of the application than not).
351 */
352#ifdef USE_ASSUMED_COLOR1
353 SP->_default_fg = COLOR_WHITE7;
354 SP->_default_bg = COLOR_BLACK0;
355#else
356 SP->_default_fg = C_MASK((1 << 9) - 1);
357 SP->_default_bg = C_MASK((1 << 9) - 1);
358#endif
359
360 /*
361 * Allow those assumed/default color assumptions to be overridden at
362 * runtime:
363 */
364 if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) {
365 int fg, bg;
366 char sep1, sep2;
367 int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
368 if (count >= 1) {
369 SP->_default_fg = (fg >= 0 && fg < max_colorscur_term->type. Numbers[13]) ? fg : C_MASK((1 << 9) - 1);
370 if (count >= 3) {
371 SP->_default_bg = (bg >= 0 && bg < max_colorscur_term->type. Numbers[13]) ? bg : C_MASK((1 << 9) - 1);
372 }
373 TR(TRACE_CHARPUT | TRACE_MOVE,
374 ("from environment assumed fg=%d, bg=%d",
375 SP->_default_fg,
376 SP->_default_bg));
377 }
378 }
379#if USE_COLORFGBG0
380 /*
381 * If rxvt's $COLORFGBG variable is set, use it to specify the assumed
382 * default colors. Note that rxvt (mis)uses bold colors, equating a bold
383 * color to that value plus 8. We'll only use the non-bold color for now -
384 * decide later if it is worth having default attributes as well.
385 */
386 if (getenv("COLORFGBG") != 0) {
387 char *p = getenv("COLORFGBG");
388 TR(TRACE_CHARPUT | TRACE_MOVE, ("decoding COLORFGBG %s", p));
389 p = extract_fgbg(p, &(SP->_default_fg));
390 p = extract_fgbg(p, &(SP->_default_bg));
391 if (*p) /* assume rxvt was compiled with xpm support */
392 p = extract_fgbg(p, &(SP->_default_bg));
393 TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d",
394 SP->_default_fg, SP->_default_bg));
395 if (SP->_default_fg >= max_colorscur_term->type. Numbers[13]) {
396 if (set_a_foregroundcur_term->type. Strings[359] != ABSENT_STRING(char *)0
397 && !strcmp(set_a_foregroundcur_term->type. Strings[359], "\033[3%p1%dm")) {
398 set_a_foregroundcur_term->type. Strings[359] = "\033[3%?%p1%{8}%>%t9%e%p1%d%;m";
399 } else {
400 SP->_default_fg %= max_colorscur_term->type. Numbers[13];
401 }
402 }
403 if (SP->_default_bg >= max_colorscur_term->type. Numbers[13]) {
404 if (set_a_backgroundcur_term->type. Strings[360] != ABSENT_STRING(char *)0
405 && !strcmp(set_a_backgroundcur_term->type. Strings[360], "\033[4%p1%dm")) {
406 set_a_backgroundcur_term->type. Strings[360] = "\033[4%?%p1%{8}%>%t9%e%p1%d%;m";
407 } else {
408 SP->_default_bg %= max_colorscur_term->type. Numbers[13];
409 }
410 }
411 }
412#endif
413#endif /* NCURSES_EXT_FUNCS */
414
415 SP->_maxclick = DEFAULT_MAXCLICK166;
416 SP->_mouse_event = no_mouse_event;
417 SP->_mouse_inline = no_mouse_inline;
418 SP->_mouse_parse = no_mouse_parse;
419 SP->_mouse_resume = no_mouse_resume;
420 SP->_mouse_wrap = no_mouse_wrap;
421 SP->_mouse_fd = -1;
422
423 /*
424 * If we've no magic cookie support, we suppress attributes that xmc would
425 * affect, i.e., the attributes that affect the rendition of a space.
426 */
427 SP->_ok_attributes = termattrs();
428 if (has_colors()) {
429 SP->_ok_attributes |= A_COLOR((((1U) << 8) - 1U) << ((0) + 8));
430 }
431#if USE_XMC_SUPPORT0
432 /*
433 * If we have no magic-cookie support compiled-in, or if it is suppressed
434 * in the environment, reset the support-flag.
435 */
436 if (magic_cookie_glitchcur_term->type. Numbers[4] >= 0) {
437 if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
438 support_cookies = FALSE0;
439 }
440 }
441#endif
442
443 if (!support_cookies && magic_cookie_glitchcur_term->type. Numbers[4] >= 0) {
444 T(("will disable attributes to work w/o magic cookies"));
445 }
446
447 if (magic_cookie_glitchcur_term->type. Numbers[4] > 0) { /* tvi, wyse */
448
449 SP->_xmc_triggers = SP->_ok_attributes & (
450 A_STANDOUT((1U) << ((8) + 8)) |
451 A_UNDERLINE((1U) << ((9) + 8)) |
452 A_REVERSE((1U) << ((10) + 8)) |
453 A_BLINK((1U) << ((11) + 8)) |
454 A_DIM((1U) << ((12) + 8)) |
455 A_BOLD((1U) << ((13) + 8)) |
456 A_INVIS((1U) << ((15) + 8)) |
457 A_PROTECT((1U) << ((16) + 8))
458 );
459#if 0
460 /*
461 * We "should" treat colors as an attribute. The wyse350 (and its
462 * clones) appear to be the only ones that have both colors and magic
463 * cookies.
464 */
465 if (has_colors()) {
466 SP->_xmc_triggers |= A_COLOR((((1U) << 8) - 1U) << ((0) + 8));
467 }
468#endif
469 SP->_xmc_suppress = SP->_xmc_triggers & (chtype) ~(A_BOLD((1U) << ((13) + 8)));
470
471 T(("magic cookie attributes %s", _traceattr(SP->_xmc_suppress)));
472 /*
473 * Supporting line-drawing may be possible. But make the regular
474 * video attributes work first.
475 */
476 acs_charscur_term->type. Strings[146] = ABSENT_STRING(char *)0;
477 ena_acscur_term->type. Strings[155] = ABSENT_STRING(char *)0;
478 enter_alt_charset_modecur_term->type. Strings[25] = ABSENT_STRING(char *)0;
479 exit_alt_charset_modecur_term->type. Strings[38] = ABSENT_STRING(char *)0;
480#if USE_XMC_SUPPORT0
481 /*
482 * To keep the cookie support simple, suppress all of the optimization
483 * hooks except for clear_screen and the cursor addressing.
484 */
485 if (support_cookies) {
486 clr_eolcur_term->type. Strings[6] = ABSENT_STRING(char *)0;
487 clr_eoscur_term->type. Strings[7] = ABSENT_STRING(char *)0;
488 set_attributescur_term->type. Strings[131] = ABSENT_STRING(char *)0;
489 }
490#endif
491 } else if (magic_cookie_glitchcur_term->type. Numbers[4] == 0) { /* hpterm */
492 }
493
494 /*
495 * If magic cookies are not supported, cancel the strings that set
496 * video attributes.
497 */
498 if (!support_cookies && magic_cookie_glitchcur_term->type. Numbers[4] >= 0) {
499 magic_cookie_glitchcur_term->type. Numbers[4] = ABSENT_NUMERIC(-1);
500 set_attributescur_term->type. Strings[131] = ABSENT_STRING(char *)0;
501 enter_blink_modecur_term->type. Strings[26] = ABSENT_STRING(char *)0;
502 enter_bold_modecur_term->type. Strings[27] = ABSENT_STRING(char *)0;
503 enter_dim_modecur_term->type. Strings[30] = ABSENT_STRING(char *)0;
504 enter_reverse_modecur_term->type. Strings[34] = ABSENT_STRING(char *)0;
505 enter_standout_modecur_term->type. Strings[35] = ABSENT_STRING(char *)0;
506 enter_underline_modecur_term->type. Strings[36] = ABSENT_STRING(char *)0;
507 }
508
509 /* initialize normal acs before wide, since we use mapping in the latter */
510#if !USE_WIDEC_SUPPORT1
511 if (_nc_unicode_locale() && _nc_locale_breaks_acs(cur_term)) {
512 acs_charscur_term->type. Strings[146] = NULL((void*)0);
513 ena_acscur_term->type. Strings[155] = NULL((void*)0);
514 enter_alt_charset_modecur_term->type. Strings[25] = NULL((void*)0);
515 exit_alt_charset_modecur_term->type. Strings[38] = NULL((void*)0);
516 set_attributescur_term->type. Strings[131] = NULL((void*)0);
517 }
518#endif
519 _nc_init_acs();
520#if USE_WIDEC_SUPPORT1
521 _nc_init_wacs();
522
523 SP->_screen_acs_fix = (_nc_unicode_locale()
524 && _nc_locale_breaks_acs(cur_term));
525#endif
526 env = _nc_get_locale();
527 SP->_legacy_coding = ((env == 0)
528 || !strcmp(env, "C")
529 || !strcmp(env, "POSIX"));
530 T(("legacy-coding %d", SP->_legacy_coding));
531
532 _nc_idcokSP->_nc_sp_idcok = TRUE1;
533 _nc_idlokSP->_nc_sp_idlok = FALSE0;
534
535 SP->oldhash = 0;
536 SP->newhash = 0;
537
538 T(("creating newscr"));
539 if ((SP->_newscr = newwin(slines, scolumns, 0, 0)) == 0)
540 returnCode(ERR)return (-1);
541
542 T(("creating curscr"));
543 if ((SP->_curscr = newwin(slines, scolumns, 0, 0)) == 0)
544 returnCode(ERR)return (-1);
545
546#if !USE_REENTRANT0
547 newscr = SP->_newscr;
548 curscr = SP->_curscr;
549#endif
550#if USE_SIZECHANGE1
551 SP->_resize = resizeterm;
552 SP->_ungetch = _nc_ungetch;
553#endif
554
555 newscr->_clear = TRUE1;
556 curscr->_clear = FALSE0;
557
558 def_shell_mode();
559 def_prog_mode();
560
561 for (rop = ripoff_stack_nc_prescreen.rippedoff;
562 rop != ripoff_sp_nc_prescreen.rsp && (rop - ripoff_stack_nc_prescreen.rippedoff) < N_RIPS5;
563 rop++) {
564
565 /* If we must simulate soft labels, grab off the line to be used.
566 We assume that we must simulate, if it is none of the standard
567 formats (4-4 or 3-2-3) for which there may be some hardware
568 support. */
569 if (rop->hook == _nc_slk_initialize)
570 if (!(num_labelscur_term->type. Numbers[8] <= 0 || !SLK_STDFMT(slk_format)(slk_format < 3)))
571 continue;
572 if (rop->hook) {
573 int count;
574 WINDOW *w;
575
576 count = (rop->line < 0) ? -rop->line : rop->line;
577 T(("ripping off %i lines at %s", count,
578 ((rop->line < 0)
579 ? "bottom"
580 : "top")));
581
582 w = newwin(count, scolumns,
583 ((rop->line < 0)
584 ? SP->_lines_avail - count
585 : 0),
586 0);
587 if (w) {
588 rop->win = w;
589 rop->hook(w, scolumns);
590 } else {
591 returnCode(ERR)return (-1);
592 }
593 if (rop->line < 0)
594 bottom_stolen += count;
595 else
596 SP->_topstolen += count;
597 SP->_lines_avail -= count;
598 }
599 }
600 /* reset the stack */
601 ripoff_sp_nc_prescreen.rsp = ripoff_stack_nc_prescreen.rippedoff;
602
603 T(("creating stdscr"));
604 assert((SP->_lines_avail + SP->_topstolen + bottom_stolen) == slines)((void)0);
605 if ((SP->_stdscr = newwin(SP->_lines_avail, scolumns, 0, 0)) == 0)
606 returnCode(ERR)return (-1);
607
608 SET_LINES(SP->_lines_avail)LINES = SP->_lines_avail;
609#if !USE_REENTRANT0
610 stdscr = SP->_stdscr;
611#endif
612
613 returnCode(OK)return (0);
614}
615
616/*
617 * The internal implementation interprets line as the number of lines to rip
618 * off from the top or bottom.
619 */
620NCURSES_EXPORT(int)int
621_nc_ripoffline(int line, int (*init) (WINDOW *, int))
622{
623 T((T_CALLED("_nc_ripoffline(%d, %p)"), line, init));
624
625 if (line != 0) {
626
627 if (ripoff_sp_nc_prescreen.rsp == 0)
628 ripoff_sp_nc_prescreen.rsp = ripoff_stack_nc_prescreen.rippedoff;
629 if (ripoff_sp_nc_prescreen.rsp >= ripoff_stack_nc_prescreen.rippedoff + N_RIPS5)
630 returnCode(ERR)return (-1);
631
632 ripoff_sp_nc_prescreen.rsp->line = line;
633 ripoff_sp_nc_prescreen.rsp->hook = init;
634 ripoff_sp_nc_prescreen.rsp++;
635 }
636
637 returnCode(OK)return (0);
638}
639
640NCURSES_EXPORT(int)int
641ripoffline(int line, int (*init) (WINDOW *, int))
642{
643 START_TRACE();
644 T((T_CALLED("ripoffline(%d,%p)"), line, init));
645
646 if (line == 0)
647 returnCode(OK)return (0);
648
649 returnCode(_nc_ripoffline((line < 0) ? -1 : 1, init))return _nc_ripoffline((line < 0) ? -1 : 1, init);
650}