+ if (SP == 0) {
+ ;
+ } else if (win) {
+ NCURSES_CH_T new_bkgd = CHDEREF(ch);
+ NCURSES_CH_T old_bkgd;
+ int y;
+ NCURSES_CH_T old_char;
+ attr_t old_attr;
+ int old_pair;
+ NCURSES_CH_T new_char;
+ attr_t new_attr;
+ int new_pair;
+
+ /* SVr4 trims color info if non-color terminal */
+ if (!SP->_pair_limit) {
+ RemAttr(new_bkgd, A_COLOR);
+ SetPair(new_bkgd, 0);
+ }
+
+ /* avoid setting background-character to a null */
+ if (CharOf(new_bkgd) == 0) {
+ NCURSES_CH_T tmp_bkgd = blank;
+ SetAttr(tmp_bkgd, AttrOf(new_bkgd));
+ SetPair(tmp_bkgd, GetPair(new_bkgd));
+ new_bkgd = tmp_bkgd;
+ }
+
+ memset(&old_bkgd, 0, sizeof(old_bkgd));
+ (void) wgetbkgrnd(win, &old_bkgd);
+
+ if (!memcmp(&old_bkgd, &new_bkgd, sizeof(new_bkgd))) {
+ T(("...unchanged"));
+ returnCode(OK);
+ }
+
+ old_char = old_bkgd;
+ RemAttr(old_char, ~A_CHARTEXT);
+ old_attr = AttrOf(old_bkgd);
+ old_pair = GetPair(old_bkgd);
+
+ if (!(old_attr & A_COLOR)) {
+ old_pair = 0;
+ }
+ T(("... old background char %s, attr %s, pair %d",
+ TraceChar(old_char), _traceattr(old_attr), old_pair));
+
+ new_char = new_bkgd;
+ RemAttr(new_char, ~A_CHARTEXT);
+ new_attr = AttrOf(new_bkgd);
+ new_pair = GetPair(new_bkgd);
+
+ /* SVr4 limits background character to printable 7-bits */
+ if (
+#if USE_WIDEC_SUPPORT
+ narrow &&
+#endif
+ !Charable(new_bkgd)) {
+ new_char = old_char;
+ }
+ if (!(new_attr & A_COLOR)) {
+ new_pair = 0;
+ }
+ T(("... new background char %s, attr %s, pair %d",
+ TraceChar(new_char), _traceattr(new_attr), new_pair));