(displayed-year): Move declaration where needed.
[emacs.git] / admin / charsets / gb180302.awk
bloba9ebc42a9a7272ebee0465ba11f7c04e33eb741d
1 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
2 # National Institute of Advanced Industrial Science and Technology (AIST)
3 # Registration Number H13PRO009
5 # This file is part of GNU Emacs.
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.
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.
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.
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 from_gb = 0;
36 to_gb = -1;
37 to_unicode = 0;
38 from_unicode = 0;
41 function decode_hex(str) {
42 n = 0;
43 len = length(str);
44 for (i = 1; i <= len; i++)
46 c = substr (str, i, 1);
47 if (c >= "0" && c <= "9")
48 n = n * 16 + (c - "0");
49 else
50 n = n * 16 + tohex[c];
52 return n;
55 function gb_to_index(gb) {
56 b0 = int(gb / 256);
57 b1 = gb % 256;
58 idx = (((b0 - 129)) * 191 + b1 - 64);
59 # if (b1 >= 128)
60 # idx--;
61 return idx
64 function index_to_gb(idx) {
65 b0 = int(idx / 191) + 129;
66 b1 = (idx % 191) + 64;
67 # if (b1 >= 127)
68 # b1++;
69 return (b0 * 256 + b1);
72 /^\#/ {
73 print;
74 next;
78 gb = gb_to_index(decode_hex(substr($1, 3, 4)));
79 unicode = decode_hex(substr($2, 3, 4));
80 if ((gb == to_gb + 1) && (unicode == to_unicode + 1))
82 to_gb++;
83 to_unicode++;
85 else
87 if (from_gb == to_gb)
88 printf "0x%04X 0x%04X\n", index_to_gb(from_gb), from_unicode;
89 else if (from_gb < to_gb)
90 printf "0x%04X-0x%04X 0x%04X\n",
91 index_to_gb(from_gb), index_to_gb(to_gb), from_unicode;
92 from_gb = to_gb = gb;
93 from_unicode = to_unicode = unicode;
97 END {
98 if (from_gb <= to_gb)
99 printf "0x%04X-0x%04X 0x%04X\n",
100 index_to_gb(from_gb), index_to_gb(to_gb), from_unicode;
103 # arch-tag: d7dbad89-a512-41a4-8ee0-ba1a4505b8c1