blob: 09066db0a282bac7bb71b6d2490b91bff2d357fe (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/*
* utf8.c:
*
* Copyright (c) 2008 James McKenzie <james@fishsoup.dhs.org>,
* All rights reserved.
*
*/
static char rcsid[] = "$Id$";
/*
* $Log$
* Revision 1.2 2008/02/22 23:39:27 james
* *** empty log message ***
*
* Revision 1.1 2008/02/22 19:12:05 james
* *** empty log message ***
*
*/
#include "project.h"
void utf8_flush(Context *c)
{
UTF8 *u=c->u;
int i;
for (i=0;i<u->utf_ptr;++i)
vt102_parse(c,u->utf_buf[i]);
u->utf_ptr=0;
u->in_utf8=0;
}
int utf8_parse(Context *c,int ch)
{
UTF8 *u=&c->u;
if (!u->in_utf8) {
/*FIXME: for the moment we bodge utf8 support*/
if (ch==0xb9) { /*CSI, not a valid utf8 start char*/
vt102_parse(c,ch);
} else if ((ch & 0xe0) == 0xc0) { /*Start of two byte unicode sequence*/
u->in_utf8=2;
u->utf_ptr=0;
u->utf_buf[u->utf_ptr++]=ch;
} else if ((ch & 0xf0) ==0xe0) { /*Start of three byte unicode sequence*/
u->in_utf8=3;
u->utf_ptr=0;
u->utf_buf[u->utf_ptr++]=ch;
} else if ((ch & 0xf8) ==0xf0) {
u->in_utf8=4;
u->utf_ptr=0;
u->utf_buf[u->utf_ptr++]=ch;
} else {
vt102_parse(c,ch);
}
} else {
if ((ch & 0xc0) != 0x80) {
utf8_flush(c);
vt102_parse(c,ch);
} else {
u->utf_buf[u->utf_ptr++]=ch;
u->in_utf8--;
}
}
}
UTF8 *utf8_new(void)
{
UTF8 *ret;
ret=(UTF8 *) malloc(sizeof(UTF8));
ret->in_utf8=0;
}
|