Mercurial > emacs
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 |
rev | line source |
---|---|
88674 | 1 BEGIN { |
2 tohex["A"] = 10; | |
3 tohex["B"] = 11; | |
4 tohex["C"] = 12; | |
5 tohex["D"] = 13; | |
6 tohex["E"] = 14; | |
7 tohex["F"] = 15; | |
8 tohex["a"] = 10; | |
9 tohex["b"] = 11; | |
10 tohex["c"] = 12; | |
11 tohex["d"] = 13; | |
12 tohex["e"] = 14; | |
13 tohex["f"] = 15; | |
14 } | |
15 | |
16 function decode_hex(str) { | |
17 n = 0; | |
18 len = length(str); | |
19 for (i = 1; i <= len; i++) | |
20 { | |
21 c = substr (str, i, 1); | |
22 if (c >= "0" && c <= "9") | |
23 n = n * 16 + (c - "0"); | |
24 else | |
25 n = n * 16 + tohex[c]; | |
26 } | |
27 return n; | |
28 } | |
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 | 37 } |
38 | |
39 function index_to_gb(idx) { | |
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 | 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 | 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 | 46 return sprintf("%02X%02X%02X%02X", b0, b1, b2, b3); |
47 } | |
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 | 52 } |
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 | 64 } |
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 | 70 } |
71 | |
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 | 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 | 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 | 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 | 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 | 100 } |
101 } | |
102 } |