annotate etc/charsets/gb18030-2.awk @ 89087:bab63e51dbaa

(set-case-syntax-pair): Remove check on byte lengths.
author Dave Love <fx@gnu.org>
date Sat, 07 Sep 2002 23:54:43 +0000
parents 264dcdcfe621
children c1527f26d513
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
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 function gb_to_index(gb) {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31 b0 = int(gb / 256);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32 b1 = gb % 256;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 idx = (((b0 - 129)) * 190 + b1 - 64);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 if (b1 >= 128)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 idx--;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
36 return idx
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 b0 = int(idx / 190) + 129;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41 b1 = (idx % 190) + 64;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 if (b1 >= 127)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 b1++;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 return (b0 * 256 + b1);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 function decode_gb(str) {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47 b0 = decode_hex(substr(str, 3, 2));
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 b1 = decode_hex(substr(str, 7, 2));
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 return (b0 * 256 + b1)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 /^<U[0-9A-F][0-9A-F][0-9A-F][0-9A-F]>/ {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 if ($2 ~ /^\\x[0-9A-F][0-9A-F]\\x[0-9A-F][0-9A-F]$/)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 unicode = decode_hex(substr($1, 3, 4));
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 gb = decode_gb($2);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57 idx = gb_to_index(gb);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 gb_table[idx] = unicode;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 END {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63 last_idx = gb_to_index(decode_hex("FEFE"));
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 from_idx = 0;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 from_unicode = gb_table[0];
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66 for (i = 1; i <= last_idx; i++)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68 gb = index_to_gb(i);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69 unicode = gb_table[i];
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 if (i - from_idx != unicode - from_unicode)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 {
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 if (i - 1 == from_idx)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 printf ("0x%04X 0x%04X\n",
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74 index_to_gb(from_idx), from_unicode);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 else
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 printf ("0x%04X-0x%04X 0x%04X\n",
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 index_to_gb(from_idx), index_to_gb(i - 1), from_unicode);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 from_idx = i;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 from_unicode=unicode;
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 }
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 if (i - from_idx != unicode - from_unicode)
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 printf ("0x%04X-0x%04X 0x%04X\n",
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 index_to_gb(from_idx), index_to_gb(i - 1), from_unicode);
264dcdcfe621 New file.
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 }