Merge from emacs--rel--22
[bpt/emacs.git] / admin / charsets / big5.awk
1 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
2 # National Institute of Advanced Industrial Science and Technology (AIST)
3 # Registration Number H13PRO009
4 #
5 # This file is part of GNU Emacs.
6 #
7 # GNU Emacs is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
10 # any later version.
11 #
12 # GNU Emacs is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Emacs; see the file COPYING. If not, write to the
19 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20 # Boston, MA 02110-1301, USA.
21
22 BEGIN {
23 tohex["A"] = 10;
24 tohex["B"] = 11;
25 tohex["C"] = 12;
26 tohex["D"] = 13;
27 tohex["E"] = 14;
28 tohex["F"] = 15;
29 tohex["a"] = 10;
30 tohex["b"] = 11;
31 tohex["c"] = 12;
32 tohex["d"] = 13;
33 tohex["e"] = 14;
34 tohex["f"] = 15;
35 }
36
37 function decode_hex(str) {
38 n = 0;
39 len = length(str);
40 for (i = 1; i <= len; i++)
41 {
42 c = substr (str, i, 1);
43 if (c >= "0" && c <= "9")
44 n = n * 16 + (c - "0");
45 else
46 n = n * 16 + tohex[c];
47 }
48 return n;
49 }
50
51 function decode_big5(big5) {
52 b0 = int(big5 / 256);
53 b1 = big5 % 256;
54 # (0xFF - 0xA1 + 0x7F - 0x40) = 157
55 # (0xA1 - (0x7F - 0x40)) = 98
56 # (0xC9 - 0xA1) * (0xFF - 0xA1 + 0x7F - 0x40) = 6280
57 if (b1 < 127)
58 idx = (b0 - 161) * 157 + (b1 - 64);
59 else
60 idx = (b0 - 161) * 157 + (b1 - 98);
61 if (b0 >= 201)
62 idx -= 6280;
63 b0 = int(idx / 94) + 33;
64 b1 = (idx % 94) + 33;
65 return (b0 * 256 + b1)
66 }
67
68 {
69 big5 = decode_hex($1);
70 code = decode_big5(big5);
71 printf "0x%04X %s\n", code, $2;
72 }
73
74
75 # arch-tag: 36f08d21-0d24-4b67-852d-a9a51299586d