_nc_insert_wch(WINDOW *win, const cchar_t *wch) { int cells = wcwidth(CharOf(CHDEREF(wch))); int cell; int code = OK; if (cells < 0) { code = winsch(win, (chtype) CharOf(CHDEREF(wch))); } else { if (cells == 0) cells = 1; if (win->_curx <= win->_maxx) { struct ldat *line = &(win->_line[win->_cury]); NCURSES_CH_T *end = &(line->text[win->_curx]); NCURSES_CH_T *temp1 = &(line->text[win->_maxx]); NCURSES_CH_T *temp2 = temp1 - cells; CHANGED_TO_EOL(line, win->_curx, win->_maxx); while (temp1 > end) *temp1-- = *temp2--; *temp1 = _nc_render(win, *wch); for (cell = 1; cell < cells; ++cell) { SetWidecExt(temp1[cell], cell); } win->_curx = (NCURSES_SIZE_T) (win->_curx + cells); } } return code; }
static int read_row(char *source, NCURSES_CH_T * prior, NCURSES_CH_T * target, int length) { while (*source != '\0' && length > 0) { #if NCURSES_WIDECHAR int n, len; source = decode_cchar(source, prior, target); len = wcwidth(target->chars[0]); if (len > 1) { SetWidecExt(CHDEREF(target), 0); for (n = 1; n < len; ++n) { target[n] = target[0]; SetWidecExt(CHDEREF(target), n); } target += (len - 1); length -= (len - 1); } #else source = decode_chtype(source, *prior, target); #endif *prior = *target; ++target; --length; } while (length-- > 0) { *target++ = blank; } /* FIXME - see what error conditions should apply if I need to return ERR */ return 0; }
static NCURSES_INLINE int #undef wbkgrnd #endif wbkgrnd(WINDOW *win, const ARG_CH_T ch) { int code = ERR; int x, y; NCURSES_CH_T new_bkgd = CHDEREF(ch); T((T_CALLED("wbkgd(%p,%s)"), (void *) win, _tracech_t(ch))); if (win) { NCURSES_CH_T old_bkgrnd; wgetbkgrnd(win, &old_bkgrnd); (void) wbkgrndset(win, CHREF(new_bkgd)); (void) wattrset(win, AttrOf(win->_nc_bkgd)); for (y = 0; y <= win->_maxy; y++) { for (x = 0; x <= win->_maxx; x++) { if (CharEq(win->_line[y].text[x], old_bkgrnd)) { win->_line[y].text[x] = win->_nc_bkgd; } else { NCURSES_CH_T wch = win->_line[y].text[x]; RemAttr(wch, (~(A_ALTCHARSET | A_CHARTEXT))); win->_line[y].text[x] = _nc_render(win, wch); } } } touchwin(win); _nc_synchook(win); code = OK; } returnCode(code); }
/* * Insert the given character, updating the current location to simplify * inserting a string. */ static int _nc_insert_wch(WINDOW *win, const cchar_t *wch) { int cells = wcwidth(CharOf(CHDEREF(wch))); int cell; if (cells <= 0) cells = 1; if (win->_curx <= win->_maxx) { struct ldat *line = &(win->_line[win->_cury]); NCURSES_CH_T *end = &(line->text[win->_curx]); NCURSES_CH_T *temp1 = &(line->text[win->_maxx]); NCURSES_CH_T *temp2 = temp1 - cells; CHANGED_TO_EOL(line, win->_curx, win->_maxx); while (temp1 > end) *temp1-- = *temp2--; *temp1 = _nc_render(win, *wch); for (cell = 1; cell < cells; ++cell) { SetWidecExt(temp1[cell], cell); } win->_curx++; } return OK; }
_nc_build_wch(WINDOW *win, ARG_CH_T ch) { char *buffer = WINDOW_EXT(win, addch_work); int len; int x = win->_curx; int y = win->_cury; mbstate_t state; wchar_t result; if ((WINDOW_EXT(win, addch_used) != 0) && (WINDOW_EXT(win, addch_x) != x || WINDOW_EXT(win, addch_y) != y)) { /* discard the incomplete multibyte character */ WINDOW_EXT(win, addch_used) = 0; TR(TRACE_VIRTPUT, ("Alert discarded multibyte on move (%d,%d) -> (%d,%d)", WINDOW_EXT(win, addch_y), WINDOW_EXT(win, addch_x), y, x)); } WINDOW_EXT(win, addch_x) = x; WINDOW_EXT(win, addch_y) = y; init_mb(state); buffer[WINDOW_EXT(win, addch_used)] = (char) CharOf(CHDEREF(ch)); WINDOW_EXT(win, addch_used) += 1; buffer[WINDOW_EXT(win, addch_used)] = '\0'; if ((len = (int) mbrtowc(&result, buffer, (size_t) WINDOW_EXT(win, addch_used), &state)) > 0) { attr_t attrs = AttrOf(CHDEREF(ch)); if_EXT_COLORS(int pair = GetPair(CHDEREF(ch))); SetChar(CHDEREF(ch), result, attrs); if_EXT_COLORS(SetPair(CHDEREF(ch), pair)); WINDOW_EXT(win, addch_used) = 0; } else if (len == -1) { /* * An error occurred. We could either discard everything, * or assume that the error was in the previous input. * Try the latter. */ TR(TRACE_VIRTPUT, ("Alert! mbrtowc returns error")); /* handle this with unctrl() */ WINDOW_EXT(win, addch_used) = 0; } return len; }
_tracecchar_t2(int bufnum, const cchar_t *ch) { char *result = _nc_trace_buf(bufnum, BUFSIZ); attr_t attr; const char *found; if (result != 0) { strcpy(result, l_brace); if (ch != 0) { attr = AttrOfD(ch); if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { (void) _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; } else if (isWidecExt(CHDEREF(ch))) { (void) _nc_trace_bufcat(bufnum, "{NAC}"); attr &= ~A_CHARTEXT; } else { PUTC_DATA; int n; PUTC_INIT; (void) _nc_trace_bufcat(bufnum, "{ "); for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { PUTC_ch = ch->chars[PUTC_i]; if (PUTC_ch == L'\0') { if (PUTC_i == 0) result = _nc_trace_bufcat(bufnum, "\\000"); break; } PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); if (PUTC_n <= 0) { if (PUTC_ch != L'\0') { /* it could not be a multibyte sequence */ (void) _nc_trace_bufcat(bufnum, _nc_tracechar(CURRENT_SCREEN, UChar(ch->chars[PUTC_i]))); } break; } for (n = 0; n < PUTC_n; n++) { if (n) (void) _nc_trace_bufcat(bufnum, ", "); (void) _nc_trace_bufcat(bufnum, _nc_tracechar(CURRENT_SCREEN, UChar(PUTC_buf[n]))); } } (void) _nc_trace_bufcat(bufnum, " }"); } if (attr != A_NORMAL) { (void) _nc_trace_bufcat(bufnum, " | "); (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } } result = _nc_trace_bufcat(bufnum, r_brace); } return result; }
_tracecchar_t2 (int bufnum, const cchar_t *ch) { char *buf = _nc_trace_buf(bufnum, BUFSIZ); attr_t attr; const char *found; strcpy(buf, l_brace); if (ch != 0) { attr = AttrOfD(ch); if ((found = _nc_altcharset_name(attr, CharOfD(ch))) != 0) { (void) _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; } else if (isWidecExt(CHDEREF(ch))) { (void) _nc_trace_bufcat(bufnum, "{NAC}"); attr &= ~A_CHARTEXT; } else { PUTC_DATA; int n; PUTC_INIT; (void) _nc_trace_bufcat(bufnum, "{ "); do { PUTC_ch = PUTC_i < CCHARW_MAX ? ch->chars[PUTC_i] : L'\0'; PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); if (PUTC_ch == L'\0') --PUTC_n; if (PUTC_n <= 0) { if (PUTC_ch != L'\0') { /* it could not be a multibyte sequence */ (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(ch->chars[PUTC_i]))); } break; } for (n = 0; n < PUTC_n; n++) { if (n) (void) _nc_trace_bufcat(bufnum, ", "); (void) _nc_trace_bufcat(bufnum, _tracechar(UChar(PUTC_buf[n]))); } ++PUTC_i; } while (PUTC_ch != L'\0'); (void) _nc_trace_bufcat(bufnum, " }"); } if (attr != A_NORMAL) { (void) _nc_trace_bufcat(bufnum, " | "); (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } } return (_nc_trace_bufcat(bufnum, r_brace)); }
setcchar(cchar_t *wcval, const wchar_t *wch, const attr_t attrs, short color_pair, const void *opts) { unsigned i; unsigned len; int code = OK; TR(TRACE_CCALLS, (T_CALLED("setcchar(%p,%s,%lu,%d,%p)"), (void *) wcval, _nc_viswbuf(wch), (unsigned long) attrs, color_pair, opts)); len = (unsigned) wcslen(wch); if (opts != NULL || (len > 1 && wcwidth(wch[0]) < 0)) { code = ERR; } else { if (len > CCHARW_MAX) len = CCHARW_MAX; /* * If we have a following spacing-character, stop at that point. We * are only interested in adding non-spacing characters. */ for (i = 1; i < len; ++i) { if (wcwidth(wch[i]) != 0) { len = i; break; } } memset(wcval, 0, sizeof(*wcval)); if (len != 0) { SetAttr(*wcval, attrs | (attr_t) ColorPair(color_pair)); SetPair(CHDEREF(wcval), color_pair); memcpy(&wcval->chars, wch, len * sizeof(wchar_t)); TR(TRACE_CCALLS, ("copy %d wchars, first is %s", len, _tracecchar_t(wcval))); } } TR(TRACE_CCALLS, (T_RETURN("%d"), code)); return (code); }
static NCURSES_INLINE void #endif wbkgrndset(WINDOW *win, const ARG_CH_T ch) { T((T_CALLED("wbkgdset(%p,%s)"), (void *) win, _tracech_t(ch))); if (win) { attr_t off = AttrOf(win->_nc_bkgd); attr_t on = AttrOf(CHDEREF(ch)); toggle_attr_off(WINDOW_ATTRS(win), off); toggle_attr_on(WINDOW_ATTRS(win), on); #if NCURSES_EXT_COLORS { int pair; if ((pair = GetPair(win->_nc_bkgd)) != 0) SET_WINDOW_PAIR(win, 0); if ((pair = GetPair(CHDEREF(ch))) != 0) SET_WINDOW_PAIR(win, pair); } #endif if (CharOf(CHDEREF(ch)) == L('\0')) { SetChar(win->_nc_bkgd, BLANK_TEXT, AttrOf(CHDEREF(ch))); if_EXT_COLORS(SetPair(win->_nc_bkgd, GetPair(CHDEREF(ch)))); } else { win->_nc_bkgd = CHDEREF(ch); } #if USE_WIDEC_SUPPORT /* * If we're compiled for wide-character support, _bkgrnd is the * preferred location for the background information since it stores * more than _bkgd. Update _bkgd each time we modify _bkgrnd, so the * macro getbkgd() will work. */ { cchar_t wch; int tmp; (void) wgetbkgrnd(win, &wch); tmp = _nc_to_char((wint_t) CharOf(wch)); win->_bkgd = (((tmp == EOF) ? ' ' : (chtype) tmp) | (AttrOf(wch) & ALL_BUT_COLOR) | ColorPair(GET_WINDOW_PAIR(win))); } #endif } returnVoid; }
_tracecchar_t2(int bufnum, const cchar_t *ch) { char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ); if (result != 0) { _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum)); if (ch != 0) { const char *found; attr_t attr = AttrOfD(ch); if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { (void) _nc_trace_bufcat(bufnum, found); attr &= ~A_ALTCHARSET; } else if (isWidecExt(CHDEREF(ch))) { (void) _nc_trace_bufcat(bufnum, "{NAC}"); attr &= ~A_CHARTEXT; } else { PUTC_DATA; int n; (void) _nc_trace_bufcat(bufnum, "{ "); for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { PUTC_ch = ch->chars[PUTC_i]; if (PUTC_ch == L'\0') { if (PUTC_i == 0) (void) _nc_trace_bufcat(bufnum, "\\000"); break; } PUTC_INIT; PUTC_n = (int) wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); if (PUTC_n <= 0) { if (PUTC_ch != L'\0') { /* it could not be a multibyte sequence */ (void) _nc_trace_bufcat(bufnum, _nc_tracechar(CURRENT_SCREEN, UChar(ch->chars[PUTC_i]))); } break; } else if (ch->chars[PUTC_i] > 255) { char temp[80]; _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) "{%d:\\u%lx}", wcwidth(ch->chars[PUTC_i]), (unsigned long) ch->chars[PUTC_i]); (void) _nc_trace_bufcat(bufnum, temp); break; } for (n = 0; n < PUTC_n; n++) { if (n) (void) _nc_trace_bufcat(bufnum, ", "); (void) _nc_trace_bufcat(bufnum, _nc_tracechar(CURRENT_SCREEN, UChar(PUTC_buf[n]))); } } (void) _nc_trace_bufcat(bufnum, " }"); } if (attr != A_NORMAL) { (void) _nc_trace_bufcat(bufnum, " | "); (void) _nc_trace_bufcat(bufnum, _traceattr2(bufnum + 20, attr)); } #if NCURSES_EXT_COLORS /* * Just in case the extended color is different from the chtype * value, trace both. */ if (ch->ext_color != PairNumber(attr)) { char temp[80]; _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) " X_COLOR{%d:%d}", ch->ext_color, PairNumber(attr)); (void) _nc_trace_bufcat(bufnum, temp); } #endif } result = _nc_trace_bufcat(bufnum, r_brace); } return result; }