Update copyright years and GPL version.
[bpt/emacs.git] / admin / charsets / big5.awk
CommitLineData
463f5630
KH
1BEGIN {
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
16function 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
30function decode_big5(big5) {
31 b0 = int(big5 / 256);
32 b1 = big5 % 256;
33# (0xFF - 0xA1 + 0x7F - 0x40) = 157
34# (0xA1 - (0x7F - 0x40)) = 98
35# (0xC9 - 0xA1) * (0xFF - 0xA1 + 0x7F - 0x40) = 6280
36 if (b1 < 127)
37 idx = (b0 - 161) * 157 + (b1 - 64);
38 else
39 idx = (b0 - 161) * 157 + (b1 - 98);
40 if (b0 >= 201)
41 idx -= 6280;
42 b0 = int(idx / 94) + 33;
43 b1 = (idx % 94) + 33;
44 return (b0 * 256 + b1)
45}
46
47{
48 big5 = decode_hex($1);
49 code = decode_big5(big5);
50 printf "0x%04X %s\n", code, $2;
51}
52
53
21e99729 54# arch-tag: 36f08d21-0d24-4b67-852d-a9a51299586d