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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/* "$Id: $"
*
* Author: Jean-Marc Lienher ( http://oksid.ch )
* Copyright 2000-2003 by O'ksi'D.
*
* This library is free software. Distribution and use rights are outlined in
* the file "COPYING" which should have been included with this file. If this
* file is missing or damaged, see the license at:
*
* http://www.fltk.org/COPYING.php
*
* Please report all bugs and problems on the following page:
*
* http://www.fltk.org/str.php
*/
/*
* read the http://www.unicode.org/Public/MAPPINGS/ and create something
* usable in C.
*/
#include <wchar.h>
#include <stdio.h>
char buffer[1000000];
int JIS0208(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
while(*ptr != '\t') { ptr++; i++; }
ptr++; i++; *(ptr+6) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (ucs)
printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int JIS0201(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+4) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (*(ptr + 1) != 'x') {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int ADOBE(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+4) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++; *(ptr+2) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
if (fmap < 1) {
printf("/* EOF */\n");
abort();
}
if (ucs) printf("/* U+%04X */ 0x%02X,\n", ucs, (unsigned char)fmap);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int JIS0212(unsigned char * ptr) {
int i = 0;
unsigned int fmap;
unsigned int ucs;
*(ptr+6) = '\0';
fmap = (unsigned int)strtoul(ptr, NULL, 16);
ptr += 7;
i += 7;
while(*ptr == ' ') { ptr++; i++; }
/* i++; ptr++; */
*(ptr+6) = '\0';
ucs = (unsigned int)strtoul(ptr, NULL, 16);
if (*(ptr + 1) != 'x') {
printf("/* EOF */\n");
abort();
}
if (ucs)
printf("/* U+%04X */ 0x%02X, 0x%02X,\n", ucs,
(fmap & 0xFF00) >> 8, fmap & 0xFF);
while(*ptr != '\0') { ptr++; i++; }
i++; ptr++;
while(*ptr != '\n') { ptr++; i++; }
i++;
return i;
}
int main(int argc, char **argv) {
char buf[80];
int len;
int i;
unsigned char *ptr;
size_t nb;
len = fread(buffer, 1, 1000000, stdin);
buffer[len] = '\0';
ptr = (unsigned char *)buffer;
while (*ptr !='\n') {ptr++; len--;};
ptr++; len--;
while (*ptr == '#') {
while (*ptr !='\n') {
ptr++;
len--;
}
ptr++;
len--;
}
while (len > 0) {
nb = 0;
if (!strcmp("jisx0208.1983-0", argv[1])) {
nb = JIS0208(ptr);
} else if (!strcmp("jisx0201.1976-0", argv[1])) {
nb = JIS0201(ptr);
} else if (!strcmp("jisx0212.1990-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("gb2312.1980-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("ksc5601.1987-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strcmp("big5-0", argv[1])) {
nb = JIS0212(ptr);
} else if (!strncmp("iso8859", argv[1], 7)) {
nb = JIS0201(ptr);
} else if (!strcmp("koi8-1", argv[1])) {
nb = JIS0201(ptr);
} else if (!strcmp("dingbats", argv[1]) ||
!strcmp("symbol", argv[1]))
{
nb = ADOBE(ptr);
} else {
len = 0;
}
ptr += nb;
len = len - nb;
}
return 0;
}
/*
* End of "$Id$".
*/
|