4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.6 2008/02/26 23:23:17 james
14 * *** empty log message ***
16 * Revision 1.5 2008/02/24 00:42:53 james
17 * *** empty log message ***
19 * Revision 1.4 2008/02/23 13:05:58 staffcvs
20 * *** empty log message ***
22 * Revision 1.3 2008/02/23 11:48:37 james
23 * *** empty log message ***
25 * Revision 1.2 2008/02/22 23:39:27 james
26 * *** empty log message ***
28 * Revision 1.1 2008/02/22 19:12:05 james
29 * *** empty log message ***
37 utf8_flush (Context * c)
45 log_f (c->l, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]);
48 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>",
49 u->utf_buf[0], u->utf_buf[1]);
52 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>",
53 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]);
57 "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>",
58 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]);
62 for (i = 0; i < u->utf_ptr; ++i)
63 vt102_parse_char (c, u->utf_buf[i]);
70 utf8_parse (Context * c, uint32_t ch)
74 if (ch == SYM_CHAR_RESET)
77 vt102_parse_char (c, ch);
83 /*FIXME: for the moment we bodge utf8 support - need to do */
84 /* L->R and R->L and double width characters */
86 { /*CSI, not a valid utf8 start char */
87 vt102_parse_char (c, ch);
89 else if ((ch & 0xe0) == 0xc0)
90 { /*Start of two byte unicode sequence */
93 u->utf_buf[u->utf_ptr++] = ch;
94 u->ch = (ch & 0x1f) << 6;
97 else if ((ch & 0xf0) == 0xe0)
98 { /*Start of three byte unicode sequence */
101 u->utf_buf[u->utf_ptr++] = ch;
102 u->ch = (ch & 0x0f) << 12;
105 else if ((ch & 0xf8) == 0xf0)
109 u->utf_buf[u->utf_ptr++] = ch;
110 u->ch = (ch & 0x07) << 18;
115 vt102_parse_char (c, ch);
120 if ((ch & 0xc0) != 0x80)
123 vt102_parse_char (c, ch);
127 u->utf_buf[u->utf_ptr++] = ch;
128 u->ch |= (ch & 0x3f) << u->sh;
133 vt102_parse_char (c, u->ch);
145 ret = (UTF8 *) malloc (sizeof (UTF8));
154 utf8_emit (TTY * t, int ch)
165 buf[0] = 0xc0 | (ch >> 6);
166 buf[1] = 0x80 | (ch & 0x3f);
170 else if (ch < 0x10000)
172 buf[0] = 0xe0 | (ch >> 12);
173 buf[1] = 0x80 | ((ch >> 6) & 0x3f);
174 buf[2] = 0x80 | (ch & 0x3f);
177 else if (ch < 0x1fffff)
179 buf[0] = 0xf0 | (ch >> 18);
180 buf[1] = 0x80 | ((ch >> 12) & 0x3f);
181 buf[2] = 0x80 | ((ch >> 6) & 0x3f);
182 buf[3] = 0x80 | (ch & 0x3f);