annotate etc/charsets/gb18030-4.awk @ 89431:c1527f26d513

Make it work for the map file included int glibc.
author Kenichi Handa <handa@m17n.org>
date Tue, 20 May 2003 13:07:55 +0000
parents 264dcdcfe621
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
1 BEGIN {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
2 tohex["A"] = 10;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
3 tohex["B"] = 11;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
4 tohex["C"] = 12;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
5 tohex["D"] = 13;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
6 tohex["E"] = 14;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
7 tohex["F"] = 15;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
8 tohex["a"] = 10;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
9 tohex["b"] = 11;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
10 tohex["c"] = 12;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
11 tohex["d"] = 13;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
12 tohex["e"] = 14;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
13 tohex["f"] = 15;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
14 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
15
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
16 function decode_hex(str) {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
17 n = 0;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
18 len = length(str);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
19 for (i = 1; i <= len; i++)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
20 {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
21 c = substr (str, i, 1);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
22 if (c >= "0" && c <= "9")
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23 n = n * 16 + (c - "0");
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24 else
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25 n = n * 16 + tohex[c];
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27 return n;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
30 function gb_to_index(gb) {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
31 b0 = int(gb / 256);
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
32 b1 = gb % 256;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
33 idx = (((b0 - 129)) * 191 + b1 - 64);
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
34 # if (b1 >= 127)
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
35 # idx--;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
36 return idx
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
37 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39 function index_to_gb(idx) {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40 b3 = (idx % 10) + 48;
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
41 idx = int(idx / 10);
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 b2 = (idx % 126) + 129;
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
43 idx = int(idx / 126);
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 b1 = (idx % 10) + 48;
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
45 b0 = int(idx / 10) + 129;
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 return sprintf("%02X%02X%02X%02X", b0, b1, b2, b3);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
49 /^\#/ {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
50 print;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
51 next;
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
54 /0x....-0x..../ {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
55 gb_from = gb_to_index(decode_hex(substr($1, 3, 4)));
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
56 gb_to = gb_to_index(decode_hex(substr($1, 10, 4)));
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
57 unicode = decode_hex(substr($2, 3, 4));
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
58 while (gb_from <= gb_to)
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
59 {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
60 table[unicode++] = 1;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
61 gb_from++;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
62 }
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
63 next;
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
66 {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
67 gb = decode_hex(substr($1, 3, 4));
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
68 unicode = decode_hex(substr($2, 3, 4));
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
69 table[unicode] = 1;
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 END {
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
73 from_gb = -1;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
74 to_gb = 0;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
75 from_i = 0;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
76 table[65536] = 1;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
77 for (i = 128; i <= 65536; i++)
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 {
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
79 if (table[i] == 0)
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 {
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
81 if (i < 55296 || i >= 57344)
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
82 {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
83 if (from_gb < 0)
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
84 {
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
85 from_gb = to_gb;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
86 from_i = i;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
87 }
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
88 to_gb++;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
89 }
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 }
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
91 else if (from_gb >= 0)
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92 {
89431
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
93 if (from_gb + 1 == to_gb)
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
94 printf "0x%s\t\t0x%04X\n",
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
95 index_to_gb(from_gb), from_i;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
96 else
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
97 printf "0x%s-0x%s\t0x%04X\n",
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
98 index_to_gb(from_gb), index_to_gb(to_gb - 1), from_i;
c1527f26d513 Make it work for the map file included int glibc.
Kenichi Handa <handa@m17n.org>
parents: 88674
diff changeset
99 from_gb = -1;
88674
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 }