+#if USE_WIDEC_SUPPORT
+ /*
+ * If this is not a valid character, there is nothing more to do.
+ */
+ if (isWidecExt(CHDEREF(ch))) {
+ TR(TRACE_CHARPUT, ("...skip"));
+ return;
+ }
+ /*
+ * Determine the number of character cells which the 'ch' value will use
+ * on the screen. It should be at least one.
+ */
+ if ((chlen = wcwidth(CharOf(CHDEREF(ch)))) <= 0) {
+ static NCURSES_CH_T blank = NewChar(BLANK_TEXT);
+
+ if (is8bits(CharOf(CHDEREF(ch)))
+ && (isprint(CharOf(CHDEREF(ch)))
+ || (SP->_legacy_coding && CharOf(CHDEREF(ch)) >= 160))) {
+ ;
+ } else {
+ ch = CHREF(blank);
+ TR(TRACE_CHARPUT, ("forced to blank"));
+ }
+ chlen = 1;
+ }
+#endif
+
+ if ((AttrOf(attr) & A_ALTCHARSET)
+ && SP->_acs_map != 0
+ && CharOfD(ch) < ACS_LEN) {
+ my_ch = CHDEREF(ch); /* work around const param */
+#if USE_WIDEC_SUPPORT
+ /*
+ * This is crude & ugly, but works most of the time. It checks if the
+ * acs_chars string specified that we have a mapping for this
+ * character, and uses the wide-character mapping when we expect the
+ * normal one to be broken (by mis-design ;-).
+ */
+ if (SP->_screen_acs_fix
+ && SP->_screen_acs_map[CharOf(my_ch)]) {
+ RemAttr(attr, A_ALTCHARSET);
+ my_ch = _nc_wacs[CharOf(my_ch)];
+ }
+#endif
+ /*
+ * If we (still) have alternate character set, it is the normal 8bit
+ * flavor. The _screen_acs_map[] array tells if the character was
+ * really in acs_chars, needed because of the way wide/normal line
+ * drawing flavors are integrated.
+ */
+ if (AttrOf(attr) & A_ALTCHARSET) {
+ int j = CharOfD(ch);
+ chtype temp = UChar(SP->_acs_map[j]);
+
+ if (!(SP->_screen_acs_map[j]))
+ RemAttr(attr, A_ALTCHARSET);
+ if (temp != 0)
+ SetChar(my_ch, temp, AttrOf(attr));
+ }
+ ch = CHREF(my_ch);
+ }
+ if (tilde_glitch && (CharOfD(ch) == L('~'))) {
+ SetChar(tilde, L('`'), AttrOf(attr));
+ ch = CHREF(tilde);
+ }
+
+ UpdateAttrs(attr);
+#if !USE_WIDEC_SUPPORT
+ /* FIXME - we do this special case for signal handling, should see how to
+ * make it work for wide characters.
+ */