Exemple #1
0
/*
 *	Translate a byte-string to a wchar_t string.
 */
wchar_t
*_strbyte2code(char *byte, wchar_t *code, int n)
{
	char		*endbyte;
	wchar_t		*bufp;
	static wchar_t	*buf;
	static int	bufsize;

	if (n < 0)
		for (n = 0; byte[n] != '\0'; ++n)
			;

	if (!code && (n + 1) > bufsize) {
		if (buf)
			free((char *)buf);
		bufsize = n + 1;
		if ((buf = (wchar_t *)malloc(bufsize * sizeof (wchar_t))) ==
		    NULL)
			bufsize = 0;
	}

	if (!code && !buf)
		return (NULL);

	bufp = code ? code : buf;
	endbyte = byte + n;

	while (byte < endbyte && *byte) {
		int		type, width;
		wchar_t		wchar;

		type = TYPE(*byte & 0377);
		width = cswidth[type];
		if (type == 1 || type == 2)
			width++;

		if (byte + width <= endbyte) {
			(void) _curs_mbtowc(&wchar, byte, width);
			*bufp++ = wchar;
		}

		byte += width;
	}
	*bufp = 0;

	return (code ? code : buf);
}
Exemple #2
0
int
winwstr(WINDOW *win, wchar_t *wstr)
{
	int	counter = 0;
	int	cy = win->_cury;
	chtype	*ptr = &(win->_y[cy][win->_curx]),
		*pmax = &(win->_y[cy][win->_maxx]);
	chtype	*p1st = &(win->_y[cy][0]);
	wchar_t	wc;
	int	sw, s;
	char	*cp, cbuf[CSMAX+1];

	while (ISCBIT(*ptr) && (p1st < ptr))
		ptr--;

	while (ptr < pmax) {
		wc = RBYTE(*ptr);
		sw = mbscrw((int)wc);
		(void) mbeucw((int)wc);

		cp = cbuf;
		for (s = 0; s < sw; s++, ptr++) {
			if ((wc = RBYTE(*ptr)) == MBIT)
				continue;
			/* LINTED */
			*cp++ = (char) wc;
			if ((wc = LBYTE(*ptr) | MBIT) == MBIT)
				continue;
			/* LINTED */
			*cp++ = (char) wc;
		}
		*cp = '\0';

		if (_curs_mbtowc(&wc, cbuf, CSMAX) <= 0)
			break;

		*wstr++ = wc;
	}

	*wstr = (wchar_t)0;

	return (counter);
}