4 * Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
9 static char rcsid[] = "$Id$";
13 * Revision 1.5 2008/02/24 00:42:53 james
14 * *** empty log message ***
16 * Revision 1.4 2008/02/23 13:05:58 staffcvs
17 * *** empty log message ***
19 * Revision 1.3 2008/02/23 11:48:37 james
20 * *** empty log message ***
22 * Revision 1.2 2008/02/22 23:39:27 james
23 * *** empty log message ***
25 * Revision 1.1 2008/02/22 19:12:05 james
26 * *** empty log message ***
34 utf8_flush (Context * c)
42 log_f (c->l, "<invalid utf-8 sequence: \\%03o>", u->utf_buf[0]);
45 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o>",
46 u->utf_buf[0], u->utf_buf[1]);
49 log_f (c->l, "<invalid utf-8 sequence: \\%03o \\%03o \\%03o>",
50 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2]);
54 "<invalid utf-8 sequence: \\%03o \\%03o \\%03o \\%03o>",
55 u->utf_buf[0], u->utf_buf[1], u->utf_buf[2], u->utf_buf[3]);
59 for (i = 0; i < u->utf_ptr; ++i)
60 vt102_parse_char (c, u->utf_buf[i]);
67 utf8_parse (Context * c, uint32_t ch)
71 if (ch == SYM_CHAR_RESET)
74 vt102_parse_char (c, ch);
80 /*FIXME: for the moment we bodge utf8 support - need to do */
81 /* L->R and R->L and double width characters */
83 { /*CSI, not a valid utf8 start char */
84 vt102_parse_char (c, ch);
86 else if ((ch & 0xe0) == 0xc0)
87 { /*Start of two byte unicode sequence */
90 u->utf_buf[u->utf_ptr++] = ch;
91 u->ch = (ch & 0x1f) << 6;
94 else if ((ch & 0xf0) == 0xe0)
95 { /*Start of three byte unicode sequence */
98 u->utf_buf[u->utf_ptr++] = ch;
99 u->ch = (ch & 0x0f) << 12;
102 else if ((ch & 0xf8) == 0xf0)
106 u->utf_buf[u->utf_ptr++] = ch;
107 u->ch = (ch & 0x07) << 18;
112 vt102_parse_char (c, ch);
117 if ((ch & 0xc0) != 0x80)
120 vt102_parse_char (c, ch);
124 u->utf_buf[u->utf_ptr++] = ch;
125 u->ch |= (ch & 0x3f) << u->sh;
130 vt102_parse_char (c, u->ch);
142 ret = (UTF8 *) malloc (sizeof (UTF8));
151 utf8_emit (TTY * t, int ch)
162 buf[0] = 0xc0 | (ch >> 6);
163 buf[1] = 0x80 | (ch & 0x3f);
167 else if (ch < 0x10000)
169 buf[0] = 0xe0 | (ch >> 12);
170 buf[1] = 0x80 | ((ch >> 6) & 0x3f);
171 buf[2] = 0x80 | (ch & 0x3f);
174 else if (ch < 0x1fffff)
176 buf[0] = 0xf0 | (ch >> 18);
177 buf[1] = 0x80 | ((ch >> 12) & 0x3f);
178 buf[2] = 0x80 | ((ch >> 6) & 0x3f);
179 buf[3] = 0x80 | (ch & 0x3f);