2 * ldisc.c: PuTTY line discipline. Sits between the input coming
3 * from keypresses in the window, and the output channel leading to
4 * the back end. Implements echo and/or local line editing,
5 * depending on what's currently configured.
15 void lpage_send(void *handle,
16 int codepage, char *buf, int len, int interactive)
18 Ldisc ldisc = (Ldisc)handle;
19 wchar_t *widebuffer = 0;
24 ldisc_send(ldisc, buf, len, interactive);
29 widebuffer = smalloc(widesize * sizeof(wchar_t));
31 wclen = mb_to_wc(codepage, 0, buf, len, widebuffer, widesize);
32 luni_send(ldisc, widebuffer, wclen, interactive);
37 void luni_send(void *handle, wchar_t * widebuf, int len, int interactive)
39 Ldisc ldisc = (Ldisc)handle;
40 int ratio = (in_utf(ldisc->term))?3:1;
46 linesize = len * ratio * 2;
47 linebuffer = smalloc(linesize * sizeof(wchar_t));
49 if (in_utf(ldisc->term)) {
50 /* UTF is a simple algorithm */
51 for (p = linebuffer, i = 0; i < len; i++) {
52 wchar_t ch = widebuf[i];
53 /* We only deal with 16-bit wide chars */
54 if ((ch&0xF800) == 0xD800) ch = '.';
58 } else if (ch < 0x800) {
59 *p++ = (0xC0 | (ch >> 6));
60 *p++ = (0x80 | (ch & 0x3F));
62 *p++ = (0xE0 | (ch >> 12));
63 *p++ = (0x80 | ((ch >> 6) & 0x3F));
64 *p++ = (0x80 | (ch & 0x3F));
69 rv = wc_to_mb(ldisc->term->ucsdata->line_codepage, 0, widebuf, len,
70 linebuffer, linesize, NULL, NULL, ldisc->term->ucsdata);
77 ldisc_send(ldisc, linebuffer, p - linebuffer, interactive);