annotate admin/charsets/gb180304.awk @ 94065:22c67e6590d0

Fix utf-8 breakage in previous commit.
author Juanma Barranquero <lekktu@gmail.com>
date Mon, 14 Apr 2008 02:00:02 +0000
parents c8aabc9d9db2
children eb2d9dfc8486
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
91417
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
1 # Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
2 # National Institute of Advanced Industrial Science and Technology (AIST)
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
3 # Registration Number H13PRO009
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
4 #
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
5 # This file is part of GNU Emacs.
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
6 #
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
7 # GNU Emacs is free software; you can redistribute it and/or modify
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
8 # it under the terms of the GNU General Public License as published by
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
9 # the Free Software Foundation; either version 3, or (at your option)
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
10 # any later version.
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
11 #
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
12 # GNU Emacs is distributed in the hope that it will be useful,
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
15 # GNU General Public License for more details.
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
16 #
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
17 # You should have received a copy of the GNU General Public License
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
18 # along with GNU Emacs; see the file COPYING. If not, write to the
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
19 # Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
20 # Boston, MA 02110-1301, USA.
c8aabc9d9db2 Add copyright and license notice.
Glenn Morris <rgm@gnu.org>
parents: 89916
diff changeset
21
88123
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
22 BEGIN {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
23 tohex["A"] = 10;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
24 tohex["B"] = 11;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
25 tohex["C"] = 12;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
26 tohex["D"] = 13;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
27 tohex["E"] = 14;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
28 tohex["F"] = 15;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
29 tohex["a"] = 10;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
30 tohex["b"] = 11;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
31 tohex["c"] = 12;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
32 tohex["d"] = 13;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
33 tohex["e"] = 14;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
34 tohex["f"] = 15;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
35 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
36
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
37 function decode_hex(str) {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
38 n = 0;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
39 len = length(str);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
40 for (i = 1; i <= len; i++)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
41 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
42 c = substr (str, i, 1);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
43 if (c >= "0" && c <= "9")
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
44 n = n * 16 + (c - "0");
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
45 else
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
46 n = n * 16 + tohex[c];
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
47 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
48 return n;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
49 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
50
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
51 function gb_to_index(gb) {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
52 b0 = int(gb / 256);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
53 b1 = gb % 256;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
54 idx = (((b0 - 129)) * 191 + b1 - 64);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
55 # if (b1 >= 127)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
56 # idx--;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
57 return idx
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
58 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
59
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
60 function index_to_gb(idx) {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
61 b3 = (idx % 10) + 48;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
62 idx = int(idx / 10);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
63 b2 = (idx % 126) + 129;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
64 idx = int(idx / 126);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
65 b1 = (idx % 10) + 48;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
66 b0 = int(idx / 10) + 129;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
67 return sprintf("%02X%02X%02X%02X", b0, b1, b2, b3);
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
68 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
69
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
70 /^\#/ {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
71 print;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
72 next;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
73 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
74
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
75 /0x....-0x..../ {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
76 gb_from = gb_to_index(decode_hex(substr($1, 3, 4)));
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
77 gb_to = gb_to_index(decode_hex(substr($1, 10, 4)));
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
78 unicode = decode_hex(substr($2, 3, 4));
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
79 while (gb_from <= gb_to)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
80 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
81 table[unicode++] = 1;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
82 gb_from++;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
83 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
84 next;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
85 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
86
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
87 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
88 gb = decode_hex(substr($1, 3, 4));
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
89 unicode = decode_hex(substr($2, 3, 4));
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
90 table[unicode] = 1;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
91 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
92
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
93 END {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
94 from_gb = -1;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
95 to_gb = 0;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
96 from_i = 0;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
97 table[65536] = 1;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
98 for (i = 128; i <= 65536; i++)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
99 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
100 if (table[i] == 0)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
101 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
102 if (i < 55296 || i >= 57344)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
103 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
104 if (from_gb < 0)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
105 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
106 from_gb = to_gb;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
107 from_i = i;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
108 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
109 to_gb++;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
110 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
111 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
112 else if (from_gb >= 0)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
113 {
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
114 if (from_gb + 1 == to_gb)
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
115 printf "0x%s\t\t0x%04X\n",
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
116 index_to_gb(from_gb), from_i;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
117 else
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
118 printf "0x%s-0x%s\t0x%04X\n",
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
119 index_to_gb(from_gb), index_to_gb(to_gb - 1), from_i;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
120 from_gb = -1;
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
121 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
122 }
375f2633d815 New directory
Kenichi Handa <handa@m17n.org>
parents:
diff changeset
123 }
89916
e0e4e6a0599f Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 88123
diff changeset
124
e0e4e6a0599f Changes from arch/CVS synchronization
Miles Bader <miles@gnu.org>
parents: 88123
diff changeset
125 # arch-tag: 8e5a22ae-610e-411f-ae17-d6e528b30d71