4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.9 2008/02/27 01:31:14 james
14 * *** empty log message ***
16 * Revision 1.8 2008/02/27 00:54:16 james
17 * *** empty log message ***
19 * Revision 1.7 2008/02/26 23:56:12 james
20 * *** empty log message ***
22 * Revision 1.6 2008/02/26 23:23:17 james
23 * *** empty log message ***
25 * Revision 1.5 2008/02/24 00:42:53 james
26 * *** empty log message ***
28 * Revision 1.4 2008/02/23 13:05:58 staffcvs
29 * *** empty log message ***
31 * Revision 1.3 2008/02/23 11:48:37 james
32 * *** empty log message ***
34 * Revision 1.2 2008/02/22 23:39:27 james
35 * *** empty log message ***
37 * Revision 1.1 2008/02/22 19:12:05 james
38 * *** empty log message ***
46 utf8_flush (Context * c)
54 log_f (c->l, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]);
57 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>",
58 u->utf_buf[0], u->utf_buf[1]);
61 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>",
62 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]);
66 "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>",
67 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]);
71 for (i = 0; i < u->utf_ptr; ++i)
72 vt102_parse_char (c, u->utf_buf[i]);
79 utf8_parse (Context * c, uint32_t ch)
83 if (ch == SYM_CHAR_RESET)
86 vt102_parse_char (c, ch);
92 /*FIXME: for the moment we bodge utf8 support - need to do */
93 /* L->R and R->L and double width characters */
95 { /*CSI, not a valid utf8 start char */
96 vt102_parse_char (c, ch);
98 else if ((ch & 0xe0) == 0xc0)
99 { /*Start of two byte unicode sequence */
102 u->utf_buf[u->utf_ptr++] = ch;
103 u->ch = (ch & 0x1f) << 6;
106 else if ((ch & 0xf0) == 0xe0)
107 { /*Start of three byte unicode sequence */
110 u->utf_buf[u->utf_ptr++] = ch;
111 u->ch = (ch & 0x0f) << 12;
114 else if ((ch & 0xf8) == 0xf0)
118 u->utf_buf[u->utf_ptr++] = ch;
119 u->ch = (ch & 0x07) << 18;
124 vt102_parse_char (c, ch);
129 if ((ch & 0xc0) != 0x80)
132 vt102_parse_char (c, ch);
136 u->utf_buf[u->utf_ptr++] = ch;
137 u->ch |= (ch & 0x3f) << u->sh;
142 vt102_parse_char (c, u->ch);
154 ret = (UTF8 *) malloc (sizeof (UTF8));
161 utf8_encode (char *ptr, int ch)
171 ptr[0] = 0xc0 | (ch >> 6);
172 ptr[1] = 0x80 | (ch & 0x3f);
175 else if (ch < 0x10000)
177 ptr[0] = 0xe0 | (ch >> 12);
178 ptr[1] = 0x80 | ((ch >> 6) & 0x3f);
179 ptr[2] = 0x80 | (ch & 0x3f);
182 else if (ch < 0x1fffff)
184 ptr[0] = 0xf0 | (ch >> 18);
185 ptr[1] = 0x80 | ((ch >> 12) & 0x3f);
186 ptr[2] = 0x80 | ((ch >> 6) & 0x3f);
187 ptr[3] = 0x80 | (ch & 0x3f);
194 utf8_emit (TTY * t, int ch)
198 i = utf8_encode (buf, ch);