1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-02 03:52:49 -05:00

Reorganised the Unicode layer somewhat: moved luni_send and

lpage_send out into the line discipline, making them _clients_ of
the Unicode layer rather than part of it. This means they can access
ldisc->term, which in turn means I've been able to remove the
temporary global variable `term'. We're slowly getting there.

[originally from svn r2143]
This commit is contained in:
Simon Tatham
2002-10-26 11:08:59 +00:00
parent 24530b945e
commit 948f95d5e8
10 changed files with 117 additions and 237 deletions

View File

@ -14,74 +14,6 @@
* are ISO8859-1.
*/
void lpage_send(void *ldisc, int codepage, char *buf, int len, int interactive)
{
ldisc_send(ldisc, buf, len, interactive);
}
void luni_send(void *ldisc, wchar_t * widebuf, int len, int interactive)
{
static char *linebuffer = 0;
static int linesize = 0;
int ratio = (in_utf(term))?6:1;
int i;
char *p;
if (len * ratio > linesize) {
sfree(linebuffer);
linebuffer = smalloc(len * ratio * 2 * sizeof(wchar_t));
linesize = len * ratio * 2;
}
if (in_utf(term)) {
/* UTF is a simple algorithm */
for (p = linebuffer, i = 0; i < len; i++) {
wchar_t ch = widebuf[i];
if ((ch&0xF800) == 0xD800) 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 if (ch < 0x200000) {
*p++ = (0xF0 | (ch >> 18));
*p++ = (0x80 | ((ch >> 12) & 0x3F));
*p++ = (0x80 | ((ch >> 6) & 0x3F));
*p++ = (0x80 | (ch & 0x3F));
} else if (ch < 0x4000000) {
*p++ = (0xF8 | (ch >> 24));
*p++ = (0x80 | ((ch >> 18) & 0x3F));
*p++ = (0x80 | ((ch >> 12) & 0x3F));
*p++ = (0x80 | ((ch >> 6) & 0x3F));
*p++ = (0x80 | (ch & 0x3F));
} else {
*p++ = (0xFC | (ch >> 30));
*p++ = (0x80 | ((ch >> 24) & 0x3F));
*p++ = (0x80 | ((ch >> 18) & 0x3F));
*p++ = (0x80 | ((ch >> 12) & 0x3F));
*p++ = (0x80 | ((ch >> 6) & 0x3F));
*p++ = (0x80 | (ch & 0x3F));
}
}
} else {
for (p = linebuffer, i = 0; i < len; i++) {
wchar_t ch = widebuf[i];
if (ch < 0x100)
*p++ = (char) ch;
else
*p++ = '.';
}
}
if (p > linebuffer)
ldisc_send(ldisc, linebuffer, p - linebuffer, interactive);
}
int is_dbcs_leadbyte(int codepage, char byte)
{
return 0; /* we don't do DBCS */
@ -109,7 +41,7 @@ int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
if (defchr)
*mbstr++ = *defchr;
else
*mbstr++ = '\xBF';
*mbstr++ = '.';
if (defused)
*defused = 1;
} else