X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=ldiscucs.c;h=1634bc43fd603520927dce87b558f720ef8cbf92;hb=510f49e405e71ba5c97875e7a019364e1ef5fac9;hp=4ac28d7ed7aa612fdb0ac3f63e70b49c0eb071a8;hpb=d36a4c3685f17057ba2c80ac471c1284b615469f;p=PuTTY.git diff --git a/ldiscucs.c b/ldiscucs.c index 4ac28d7e..1634bc43 100644 --- a/ldiscucs.c +++ b/ldiscucs.c @@ -13,7 +13,7 @@ #include "ldisc.h" void lpage_send(void *handle, - int codepage, char *buf, int len, int interactive) + int codepage, const char *buf, int len, int interactive) { Ldisc ldisc = (Ldisc)handle; wchar_t *widebuffer = 0; @@ -34,7 +34,7 @@ void lpage_send(void *handle, sfree(widebuffer); } -void luni_send(void *handle, wchar_t * widebuf, int len, int interactive) +void luni_send(void *handle, const wchar_t *widebuf, int len, int interactive) { Ldisc ldisc = (Ldisc)handle; int ratio = (in_utf(ldisc->term))?3:1; @@ -49,19 +49,38 @@ void luni_send(void *handle, wchar_t * widebuf, int len, int interactive) if (in_utf(ldisc->term)) { /* UTF is a simple algorithm */ for (p = linebuffer, i = 0; i < len; i++) { - wchar_t ch = widebuf[i]; - /* We only deal with 16-bit wide chars */ - if ((ch&0xF800) == 0xD800) ch = '.'; + unsigned long ch = widebuf[i]; + + if (IS_SURROGATE(ch)) { +#ifdef PLATFORM_IS_UTF16 + if (i+1 < len) { + unsigned long ch2 = widebuf[i+1]; + if (IS_SURROGATE_PAIR(ch, ch2)) { + ch = FROM_SURROGATES(ch, ch2); + 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)); + *p++ = (char) (0xC0 | (ch >> 6)); + *p++ = (char) (0x80 | (ch & 0x3F)); + } else if (ch < 0x10000) { + *p++ = (char) (0xE0 | (ch >> 12)); + *p++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *p++ = (char) (0x80 | (ch & 0x3F)); } else { - *p++ = (0xE0 | (ch >> 12)); - *p++ = (0x80 | ((ch >> 6) & 0x3F)); - *p++ = (0x80 | (ch & 0x3F)); + *p++ = (char) (0xF0 | (ch >> 18)); + *p++ = (char) (0x80 | ((ch >> 12) & 0x3F)); + *p++ = (char) (0x80 | ((ch >> 6) & 0x3F)); + *p++ = (char) (0x80 | (ch & 0x3F)); } } } else {