4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.7 2008/02/26 23:56:12 james
14 * *** empty log message ***
16 * Revision 1.6 2008/02/26 23:23:17 james
17 * *** empty log message ***
19 * Revision 1.5 2008/02/24 00:42:53 james
20 * *** empty log message ***
22 * Revision 1.4 2008/02/23 13:05:58 staffcvs
23 * *** empty log message ***
25 * Revision 1.3 2008/02/23 11:48:37 james
26 * *** empty log message ***
28 * Revision 1.2 2008/02/22 23:39:27 james
29 * *** empty log message ***
31 * Revision 1.1 2008/02/22 19:12:05 james
32 * *** empty log message ***
40 utf8_flush (Context * c)
48 log_f (c->l, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]);
51 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>",
52 u->utf_buf[0], u->utf_buf[1]);
55 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>",
56 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]);
60 "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>",
61 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]);
65 for (i = 0; i < u->utf_ptr; ++i)
66 vt102_parse_char (c, u->utf_buf[i]);
73 utf8_parse (Context * c, uint32_t ch)
77 if (ch == SYM_CHAR_RESET)
80 vt102_parse_char (c, ch);
86 /*FIXME: for the moment we bodge utf8 support - need to do */
87 /* L->R and R->L and double width characters */
89 { /*CSI, not a valid utf8 start char */
90 vt102_parse_char (c, ch);
92 else if ((ch & 0xe0) == 0xc0)
93 { /*Start of two byte unicode sequence */
96 u->utf_buf[u->utf_ptr++] = ch;
97 u->ch = (ch & 0x1f) << 6;
100 else if ((ch & 0xf0) == 0xe0)
101 { /*Start of three byte unicode sequence */
104 u->utf_buf[u->utf_ptr++] = ch;
105 u->ch = (ch & 0x0f) << 12;
108 else if ((ch & 0xf8) == 0xf0)
112 u->utf_buf[u->utf_ptr++] = ch;
113 u->ch = (ch & 0x07) << 18;
118 vt102_parse_char (c, ch);
123 if ((ch & 0xc0) != 0x80)
126 vt102_parse_char (c, ch);
130 u->utf_buf[u->utf_ptr++] = ch;
131 u->ch |= (ch & 0x3f) << u->sh;
136 vt102_parse_char (c, u->ch);
148 ret = (UTF8 *) malloc (sizeof (UTF8));
157 utf8_emit (TTY * t, int ch)
168 buf[0] = 0xc0 | (ch >> 6);
169 buf[1] = 0x80 | (ch & 0x3f);
173 else if (ch < 0x10000)
175 buf[0] = 0xe0 | (ch >> 12);
176 buf[1] = 0x80 | ((ch >> 6) & 0x3f);
177 buf[2] = 0x80 | (ch & 0x3f);
180 else if (ch < 0x1fffff)
182 buf[0] = 0xf0 | (ch >> 18);
183 buf[1] = 0x80 | ((ch >> 12) & 0x3f);
184 buf[2] = 0x80 | ((ch >> 6) & 0x3f);
185 buf[3] = 0x80 | (ch & 0x3f);