示例#1
0
/* re_addc():
 *	Draw c, expanding tabs, control chars etc.
 */
static void
re_addc(EditLine *el, wint_t c)
{
	switch (ct_chr_class(c)) {
	case CHTYPE_TAB:        /* expand the tab */
		for (;;) {
			re_putc(el, ' ', 1);
			if ((el->el_refresh.r_cursor.h & 07) == 0)
				break;			/* go until tab stop */
		}
		break;
	case CHTYPE_NL: {
		int oldv = el->el_refresh.r_cursor.v;
		re_putc(el, '\0', 0);			/* assure end of line */
		if (oldv == el->el_refresh.r_cursor.v)	/* XXX */
			re_nextline(el);
		break;
	}
	case CHTYPE_PRINT:
		re_putc(el, c, 1);
		break;
	default: {
		wchar_t visbuf[VISUAL_WIDTH_MAX];
		ssize_t i, n =
		    ct_visual_char(visbuf, VISUAL_WIDTH_MAX, c);
		for (i = 0; n-- > 0; ++i)
		    re_putc(el, visbuf[i], 1);
		break;
	}
	}
}
示例#2
0
libedit_private const wchar_t *
ct_visual_string(const wchar_t *s, ct_buffer_t *conv)
{
	wchar_t *dst;
	ssize_t used;

	if (!s)
		return NULL;

	if (ct_conv_wbuff_resize(conv, CT_BUFSIZ) == -1)
		return NULL;

	used = 0;
	dst = conv->wbuff;
	while (*s) {
		used = ct_visual_char(dst,
		    conv->wsize - (size_t)(dst - conv->wbuff), *s);
		if (used != -1) {
			++s;
			dst += used;
			continue;
		}

		/* failed to encode, need more buffer space */
		used = dst - conv->wbuff;
		if (ct_conv_wbuff_resize(conv, conv->wsize + CT_BUFSIZ) == -1)
			return NULL;
		dst = conv->wbuff + used;
	}

	if (dst >= (conv->wbuff + conv->wsize)) { /* sigh */
		used = dst - conv->wbuff;
		if (ct_conv_wbuff_resize(conv, conv->wsize + CT_BUFSIZ) == -1)
			return NULL;
		dst = conv->wbuff + used;
	}

	*dst = L'\0';
	return conv->wbuff;
}