/* * Add to 'win' a character at(curx, cury). */ int waddwch(WINDOW *win, chtype c) { int width; char buf[CSMAX]; chtype a; wchar_t code; char *p; a = c & A_WATTRIBUTES; code = c & A_WCHARTEXT; /* translate the process code to character code */ if ((width = _curs_wctomb(buf, code & TRIM)) < 0) return (ERR); /* now call waddch to do the real work */ p = buf; while (width--) if (waddch(win, a|(0xFF & *p++)) == ERR) return (ERR); return (OK); }
/* * Translate a string of wchar_t to a byte string. * code: the input code string * byte: if not NULL, space to store the output string * n: maximum number of codes to be translated. */ char *_strcode2byte(wchar_t *code, char *byte, int n) { char *bufp; wchar_t *endcode; static char *buf; static int bufsize; /* compute the length of the code string */ if (n < 0) for (n = 0; code[n] != 0; ++n) ; /* get space to store the translated string */ if (!byte && (n*CSMAX+1) > bufsize) { if (buf) free(buf); bufsize = n * CSMAX + 1; if ((buf = malloc(bufsize * sizeof (char))) == NULL) bufsize = 0; } /* no space to do it */ if (!byte && !buf) return (NULL); /* start the translation */ bufp = byte ? byte : buf; endcode = code+n; while (code < endcode && *code) { bufp += _curs_wctomb(bufp, *code & TRIM); ++code; } *bufp = '\0'; return (byte ? byte : buf); }
/* * Add ncols worth of data to win, using string as input. * Return the number of chtypes copied. * Note: chtype contains 32/16 bit process code. */ int waddwchnstr(WINDOW *win, chtype *string, int ncols) { int my_x = win->_curx; int my_y = win->_cury; short my_maxx; int counter; chtype *ptr = &(win->_y[my_y][my_x]); chtype *sptr = ptr; char mbbuf[CSMAX+1]; int mp, s, scrw; chtype rawc; chtype attr; short my_x1 = win->_curx; while (ISCBIT(*ptr)) { ptr--; my_x1--; } while (ptr < sptr) *ptr++ = win->_bkgd; if (ncols == -1) ncols = MAXINT; counter = win->_maxx - my_x; while ((ncols > 0) && (*string) && (counter > 0)) { attr = *string & A_WATTRIBUTES; rawc = *string & A_WCHARTEXT; /* conver wchar_t to mbuti byte string */ for (mp = 0; mp < sizeof (mbbuf); mp++) mbbuf[mp] = '\0'; if (_curs_wctomb(mbbuf, rawc) <= 0) goto out; /* if there are no cols on screen, end */ if ((scrw = wcscrw(rawc)) > counter) goto out; if (rawc & WCHAR_CSMASK) { /* store multi-byte string into chtype */ for (s = 0, mp = 0; s < scrw; s++, mp += 2) { *ptr = _CHAR(RBYTE(mbbuf[mp]) | RBYTE(mbbuf[mp + 1]) << 8) | CBIT; SETMBIT(*ptr); if (mp > 0) SETCBIT(*ptr); else CLRCBIT(*ptr); *ptr |= attr; ptr++; } } else { /* store single-byte string into chtype */ *ptr = mbbuf[0]; *ptr |= attr; ptr++; } ncols--; string++; counter -= scrw; } out : while (ISCBIT(*ptr)) *ptr++ = win->_bkgd; /* LINTED */ my_maxx = (short) (ptr - sptr + my_x); if (my_x1 < win->_firstch[my_y]) win->_firstch[my_y] = my_x1; if (my_maxx > win->_lastch[my_y]) win->_lastch[my_y] = my_maxx; win->_flags |= _WINCHANGED; /* sync with ancestor structures */ if (win->_sync) wsyncup(win); return (win->_immed ? wrefresh(win) : OK); }