Exemplo n.º 1
0
static int plen(Ldisc ldisc, unsigned char c)
{
    if ((c >= 32 && c <= 126) || (c >= 160 && !in_utf(ldisc->term)))
	return 1;
    else if (c < 128)
	return 2;		       /* ^x for some x */
    else if (in_utf(ldisc->term) && c >= 0xC0)
	return 1;		       /* UTF-8 introducer character
					* (FIXME: combining / wide chars) */
    else if (in_utf(ldisc->term) && c >= 0x80 && c < 0xC0)
	return 0;		       /* UTF-8 followup character */
    else
	return 4;		       /* <XY> hex representation */
}
Exemplo n.º 2
0
static int char_start(Ldisc ldisc, unsigned char c)
{
    if (in_utf(ldisc->term))
	return (c < 0x80 || c >= 0xC0);
    else
	return 1;
}
Exemplo n.º 3
0
static bool char_start(Ldisc *ldisc, unsigned char c)
{
    if (in_utf(ldisc->term))
	return (c < 0x80 || c >= 0xC0);
    else
	return true;
}
Exemplo n.º 4
0
static void pwrite(Ldisc ldisc, unsigned char c)
{
    if ((c >= 32 && c <= 126) ||
	(!in_utf(ldisc->term) && c >= 0xA0) ||
	(in_utf(ldisc->term) && c >= 0x80)) {
	c_write(ldisc, (char *)&c, 1);
    } else if (c < 128) {
	char cc[2];
	cc[1] = (c == 127 ? '?' : c + 0x40);
	cc[0] = '^';
	c_write(ldisc, cc, 2);
    } else {
	char cc[5];
	sprintf(cc, "<%02X>", c);
	c_write(ldisc, cc, 4);
    }
}
Exemplo n.º 5
0
void luni_send(void *handle, wchar_t * widebuf, int len, int interactive)
{
    Ldisc ldisc = (Ldisc)handle;
    int ratio = (in_utf(ldisc->term))?3:1;
    char *linebuffer;
    int linesize;
    int i;
    char *p;

    linesize = len * ratio * 2;
    linebuffer = snewn(linesize, char);

    if (in_utf(ldisc->term)) {
	/* UTF is a simple algorithm */
	for (p = linebuffer, i = 0; i < len; i++) {
	    unsigned long ch = widebuf[i];

	    if ((ch & 0xF800) == 0xD800) {
#ifdef PLATFORM_IS_UTF16
		if (i+1 < len) {
		    unsigned long ch2 = widebuf[i+1];
		    if ((ch & 0xFC00) == 0xD800 &&
			(ch2 & 0xFC00) == 0xDC00) {
			ch = 0x10000 + ((ch & 0x3FF) << 10) + (ch2 & 0x3FF);
			i++;
		    }
		} else
#endif
		{
		    /* Unrecognised UTF-16 sequence */
		    ch = '.';
		}
	    }

	    if (ch < 0x80) {
		*p++ = (char) (ch);
	    } else if (ch < 0x800) {
		*p++ = (0xC0 | (ch >> 6));
		*p++ = (0x80 | (ch & 0x3F));
	    } else if (ch < 0x10000) {
		*p++ = (0xE0 | (ch >> 12));
		*p++ = (0x80 | ((ch >> 6) & 0x3F));
		*p++ = (0x80 | (ch & 0x3F));
	    } else {