4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.8 2008/02/27 00:54:16 james
14 * *** empty log message ***
16 * Revision 1.7 2008/02/26 23:56:12 james
17 * *** empty log message ***
19 * Revision 1.6 2008/02/26 23:23:17 james
20 * *** empty log message ***
22 * Revision 1.5 2008/02/24 00:42:53 james
23 * *** empty log message ***
25 * Revision 1.4 2008/02/23 13:05:58 staffcvs
26 * *** empty log message ***
28 * Revision 1.3 2008/02/23 11:48:37 james
29 * *** empty log message ***
31 * Revision 1.2 2008/02/22 23:39:27 james
32 * *** empty log message ***
34 * Revision 1.1 2008/02/22 19:12:05 james
35 * *** empty log message ***
43 utf8_flush (Context * c)
51 log_f (c->l, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]);
54 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>",
55 u->utf_buf[0], u->utf_buf[1]);
58 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>",
59 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]);
63 "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>",
64 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]);
68 for (i = 0; i < u->utf_ptr; ++i)
69 vt102_parse_char (c, u->utf_buf[i]);
76 utf8_parse (Context * c, uint32_t ch)
80 if (ch == SYM_CHAR_RESET)
83 vt102_parse_char (c, ch);
89 /*FIXME: for the moment we bodge utf8 support - need to do */
90 /* L->R and R->L and double width characters */
92 { /*CSI, not a valid utf8 start char */
93 vt102_parse_char (c, ch);
95 else if ((ch & 0xe0) == 0xc0)
96 { /*Start of two byte unicode sequence */
99 u->utf_buf[u->utf_ptr++] = ch;
100 u->ch = (ch & 0x1f) << 6;
103 else if ((ch & 0xf0) == 0xe0)
104 { /*Start of three byte unicode sequence */
107 u->utf_buf[u->utf_ptr++] = ch;
108 u->ch = (ch & 0x0f) << 12;
111 else if ((ch & 0xf8) == 0xf0)
115 u->utf_buf[u->utf_ptr++] = ch;
116 u->ch = (ch & 0x07) << 18;
121 vt102_parse_char (c, ch);
126 if ((ch & 0xc0) != 0x80)
129 vt102_parse_char (c, ch);
133 u->utf_buf[u->utf_ptr++] = ch;
134 u->ch |= (ch & 0x3f) << u->sh;
139 vt102_parse_char (c, u->ch);
151 ret = (UTF8 *) malloc (sizeof (UTF8));
157 int utf8_encode (char *ptr, int ch)
167 ptr[0] = 0xc0 | (ch >> 6);
168 ptr[1] = 0x80 | (ch & 0x3f);
171 else if (ch < 0x10000)
173 ptr[0] = 0xe0 | (ch >> 12);
174 ptr[1] = 0x80 | ((ch >> 6) & 0x3f);
175 ptr[2] = 0x80 | (ch & 0x3f);
178 else if (ch < 0x1fffff)
180 ptr[0] = 0xf0 | (ch >> 18);
181 ptr[1] = 0x80 | ((ch >> 12) & 0x3f);
182 ptr[2] = 0x80 | ((ch >> 6) & 0x3f);
183 ptr[3] = 0x80 | (ch & 0x3f);
190 utf8_emit (TTY * t, int ch)
194 i=utf8_encode(buf,ch);