+ /*
+ * This actually allocates the screen structure, and saves the original
+ * terminal settings.
+ */
+ if (_nc_setupscreen(LINES,
+ COLS,
+ _ofp,
+ _nc_prescreen.filter_mode,
+ slk_format) == ERR) {
+ _nc_set_screen(current);
+ result = 0;
+ } else {
+#ifdef USE_TERM_DRIVER
+ TERMINAL_CONTROL_BLOCK *TCB;
+#else
+ SP_PARM = CURRENT_SCREEN;
+#endif
+ assert(SP_PARM != 0);
+ cols = *(ptrCols(SP_PARM));
+#ifdef USE_TERM_DRIVER
+ TCB = (TERMINAL_CONTROL_BLOCK *) new_term;
+ TCB->csp = SP_PARM;
+#endif
+ numlab = NumLabels;
+
+ /*
+ * In setupterm() we did a set_curterm(), but it was before we set
+ * CURRENT_SCREEN. So the "current" screen's terminal pointer was
+ * overwritten with a different terminal. Later, in
+ * _nc_setupscreen(), we set CURRENT_SCREEN and the terminal
+ * pointer in the new screen.
+ *
+ * Restore the terminal-pointer for the pre-existing screen, if
+ * any.
+ */
+ if (current)
+ current->_term = its_term;
+
+ /* if the terminal type has real soft labels, set those up */
+ if (slk_format && NumLabels > 0 && SLK_STDFMT(slk_format))
+ _nc_slk_initialize(stdscr, COLS);
+
+ SP_PARM->_ifd = fileno(_ifp);
+ NCURSES_SP_NAME(typeahead) (NCURSES_SP_ARGx fileno(_ifp));
+#ifdef TERMIOS
+ SP_PARM->_use_meta = ((cur_term->Ottyb.c_cflag & CSIZE) == CS8 &&
+ !(cur_term->Ottyb.c_iflag & ISTRIP));
+#else
+ SP_PARM->_use_meta = FALSE;
+#endif
+ SP_PARM->_endwin = FALSE;
+#ifndef USE_TERM_DRIVER
+ /*
+ * Check whether we can optimize scrolling under dumb terminals in
+ * case we do not have any of these capabilities, scrolling
+ * optimization will be useless.
+ */
+ SP_PARM->_scrolling = ((scroll_forward && scroll_reverse) ||
+ ((parm_rindex ||
+ parm_insert_line ||
+ insert_line) &&
+ (parm_index ||
+ parm_delete_line ||
+ delete_line)));
+#endif