+ /* implement filter mode */
+ if (filtered) {
+ slines = 1;
+ SET_LINES(slines);
+#ifdef USE_TERM_DRIVER
+ CallDriver(sp, td_setfilter);
+#else
+ /* *INDENT-EQLS* */
+ clear_screen = ABSENT_STRING;
+ cursor_address = ABSENT_STRING;
+ cursor_down = ABSENT_STRING;
+ cursor_up = ABSENT_STRING;
+ parm_down_cursor = ABSENT_STRING;
+ parm_up_cursor = ABSENT_STRING;
+ row_address = ABSENT_STRING;
+ cursor_home = carriage_return;
+
+ if (back_color_erase)
+ clr_eos = ABSENT_STRING;
+
+#endif
+ T(("filter screensize %dx%d", slines, scolumns));
+ }
+#ifdef __DJGPP__
+ T(("setting output mode to binary"));
+ fflush(output);
+ setmode(output, O_BINARY);
+#endif
+ NCURSES_SP_NAME(_nc_set_buffer) (NCURSES_SP_ARGx output, TRUE);
+ sp->_lines = (NCURSES_SIZE_T) slines;
+ sp->_lines_avail = (NCURSES_SIZE_T) slines;
+ sp->_columns = (NCURSES_SIZE_T) scolumns;
+
+ fflush(output);
+ sp->_ofd = output ? fileno(output) : -1;
+ sp->_ofp = output;
+ sp->out_limit = (size_t) ((2 + slines) * (6 + scolumns));
+ if ((sp->out_buffer = malloc(sp->out_limit)) == 0)
+ sp->out_limit = 0;
+ sp->out_inuse = 0;
+
+ SP_PRE_INIT(sp);
+ 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 = COLOR_DEFAULT;
+ sp->_default_bg = COLOR_DEFAULT;
+#endif
+
+ /*
+ * Allow those assumed/default color assumptions to be overridden at
+ * runtime:
+ */
+ if ((env = getenv("NCURSES_ASSUMED_COLORS")) != 0) {
+ int fg, bg;
+ char sep1, sep2;
+ int count = sscanf(env, "%d%c%d%c", &fg, &sep1, &bg, &sep2);
+ if (count >= 1) {
+ sp->_default_fg = ((fg >= 0 && fg < MaxColors) ? fg : COLOR_DEFAULT);
+ if (count >= 3) {
+ sp->_default_bg = ((bg >= 0 && bg < MaxColors) ? bg : COLOR_DEFAULT);
+ }
+ TR(TRACE_CHARPUT | TRACE_MOVE,
+ ("from environment assumed fg=%d, bg=%d",
+ sp->_default_fg,
+ sp->_default_bg));
+ }
+ }
+#if USE_COLORFGBG
+ /*
+ * If rxvt's $COLORFGBG variable is set, use it to specify the assumed
+ * default colors. Note that rxvt (mis)uses bold colors, equating a bold
+ * color to that value plus 8. We'll only use the non-bold color for now -
+ * decide later if it is worth having default attributes as well.
+ */
+ if (getenv("COLORFGBG") != 0) {
+ const char *p = getenv("COLORFGBG");
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("decoding COLORFGBG %s", p));
+ p = extract_fgbg(p, &(sp->_default_fg));
+ p = extract_fgbg(p, &(sp->_default_bg));
+ if (*p) /* assume rxvt was compiled with xpm support */
+ p = extract_fgbg(p, &(sp->_default_bg));
+ TR(TRACE_CHARPUT | TRACE_MOVE, ("decoded fg=%d, bg=%d",
+ sp->_default_fg, sp->_default_bg));
+ if (sp->_default_fg >= MaxColors) {
+ if (set_a_foreground != ABSENT_STRING
+ && !strcmp(set_a_foreground, "\033[3%p1%dm")) {
+ set_a_foreground = strdup("\033[3%?%p1%{8}%>%t9%e%p1%d%;m");
+ } else {
+ sp->_default_fg %= MaxColors;
+ }
+ }
+ if (sp->_default_bg >= MaxColors) {
+ if (set_a_background != ABSENT_STRING
+ && !strcmp(set_a_background, "\033[4%p1%dm")) {
+ set_a_background = strdup("\033[4%?%p1%{8}%>%t9%e%p1%d%;m");
+ } else {
+ sp->_default_bg %= MaxColors;
+ }
+ }
+ }
+#endif
+#endif /* NCURSES_EXT_FUNCS */
+
+ sp->_maxclick = DEFAULT_MAXCLICK;
+ sp->_mouse_event = no_mouse_event;
+ sp->_mouse_inline = no_mouse_inline;
+ sp->_mouse_parse = no_mouse_parse;
+ sp->_mouse_resume = no_mouse_resume;
+ sp->_mouse_wrap = no_mouse_wrap;
+ sp->_mouse_fd = -1;
+
+ /*
+ * If we've no magic cookie support, we suppress attributes that xmc would
+ * affect, i.e., the attributes that affect the rendition of a space.
+ */
+ sp->_ok_attributes = NCURSES_SP_NAME(termattrs) (NCURSES_SP_ARG);
+ if (NCURSES_SP_NAME(has_colors) (NCURSES_SP_ARG)) {
+ sp->_ok_attributes |= A_COLOR;
+ }
+#ifdef USE_TERM_DRIVER
+ _nc_cookie_init(sp);
+#else
+#if USE_XMC_SUPPORT
+ /*
+ * If we have no magic-cookie support compiled-in, or if it is suppressed
+ * in the environment, reset the support-flag.
+ */
+ if (magic_cookie_glitch >= 0) {
+ if (getenv("NCURSES_NO_MAGIC_COOKIE") != 0) {
+ support_cookies = FALSE;
+ }
+ }
+#endif