+#if NCURSES_SP_FUNCS
+ SCREEN *sp = CURRENT_SCREEN;
+#endif
+ char *env;
+ int bottom_stolen = 0;
+ bool support_cookies = USE_XMC_SUPPORT;
+ ripoff_t *rop;
+
+ T((T_CALLED("_nc_setupscreen(%d, %d, %p, %d, %d)"),
+ slines, scolumns, output, filtered, slk_format));
+
+ assert(SP == 0); /* has been reset in newterm() ! */
+ if (!_nc_alloc_screen()
+ || ((SP->_acs_map = typeCalloc(chtype, ACS_LEN)) == 0)
+ || ((SP->_screen_acs_map = typeCalloc(bool, ACS_LEN)) == 0)) {
+ returnCode(ERR);
+ }
+
+ T(("created SP %p", SP));
+#if NCURSES_SP_FUNCS
+ sp = SP; /* fixup so SET_LINES and SET_COLS works */
+#endif
+ SP->_next_screen = _nc_screen_chain;
+ _nc_screen_chain = SP;
+
+ if ((SP->_current_attr = typeCalloc(NCURSES_CH_T, 1)) == 0)
+ returnCode(ERR);
+
+ /*
+ * We should always check the screensize, just in case.
+ */
+ _nc_get_screensize(SP, &slines, &scolumns);
+ SET_LINES(slines);
+ SET_COLS(scolumns);
+ T((T_CREATE("screen %s %dx%d"), termname(), LINES, COLS));
+
+ SP->_filtered = filtered;
+
+ /* implement filter mode */
+ if (filtered) {
+ slines = 1;
+ SET_LINES(slines);
+ clear_screen = 0;
+ cursor_down = parm_down_cursor = 0;
+ cursor_address = 0;
+ cursor_up = parm_up_cursor = 0;
+ row_address = 0;
+
+ cursor_home = carriage_return;
+ T(("filter screensize %dx%d", LINES, COLS));
+ }
+#ifdef __DJGPP__
+ T(("setting output mode to binary"));
+ fflush(output);
+ setmode(output, O_BINARY);
+#endif
+ _nc_set_buffer(output, TRUE);
+ SP->_term = cur_term;
+ SP->_lines = slines;
+ SP->_lines_avail = slines;
+ SP->_columns = scolumns;
+ SP->_cursrow = -1;
+ SP->_curscol = -1;
+ SP->_nl = TRUE;
+ SP->_raw = FALSE;
+ SP->_cbreak = 0;
+ SP->_echo = TRUE;
+ SP->_fifohead = -1;
+ SP->_endwin = TRUE;
+ SP->_ofp = output;
+ SP->_cursor = -1; /* cannot know real cursor shape */
+
+ SetNoPadding(SP);
+
+#if NCURSES_EXT_FUNCS
+ SP->_default_color = FALSE;
+ SP->_has_sgr_39_49 = FALSE;
+
+ /*
+ * Set our assumption of the terminal's default foreground and background
+ * colors. The curs_color man-page states that we can assume that the
+ * background is black. The origin of this assumption appears to be
+ * terminals that displayed colored text, but no colored backgrounds, e.g.,
+ * the first colored terminals around 1980. More recent ones with better
+ * technology can display not only colored backgrounds, but all
+ * combinations. So a terminal might be something other than "white" on
+ * black (green/black looks monochrome too), but black on white or even
+ * on ivory.
+ *
+ * White-on-black is the simplest thing to use for monochrome. Almost
+ * all applications that use color paint both text and background, so
+ * the distinction is moot. But a few do not - which is why we leave this
+ * configurable (a better solution is to use assume_default_colors() for
+ * the rare applications that do require that sort of appearance, since
+ * is appears that more users expect to be able to make a white-on-black
+ * or black-on-white display under control of the application than not).
+ */
+#ifdef USE_ASSUMED_COLOR
+ SP->_default_fg = COLOR_WHITE;
+ SP->_default_bg = COLOR_BLACK;
+#else
+ SP->_default_fg = C_MASK;
+ SP->_default_bg = C_MASK;