- /* if the terminal type has real soft labels, set those up */
- if (slk_format && num_labels > 0 && SLK_STDFMT(slk_format))
- _nc_slk_initialize(stdscr, COLS);
-
- SP->_ifd = fileno(ifp);
- SP->_checkfd = fileno(ifp);
- typeahead(fileno(ifp));
+ if (_nc_setupscreen(LINES,
+ COLS,
+ ofp,
+ _nc_prescreen.filter_mode,
+ slk_format) == ERR) {
+ _nc_set_screen(current);
+ result = 0;
+ } else {
+ assert(SP_PARM != 0);
+ /*
+ * In setupterm() we did a set_curterm(), but it was before we set
+ * SP. So the "current" screen's terminal pointer was overwritten
+ * with a different terminal. Later, in _nc_setupscreen(), we set
+ * SP 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 && num_labels > 0 && SLK_STDFMT(slk_format))
+ _nc_slk_initialize(stdscr, COLS);
+
+ SP->_ifd = fileno(ifp);
+ typeahead(fileno(ifp));