comparison admin/charsets/cp932.awk @ 89745:708856d4c65b

New file.
author Kenichi Handa <handa@m17n.org>
date Sun, 25 Jan 2004 23:35:58 +0000
parents
children cce22763e5b1
comparison
equal deleted inserted replaced
89744:04403873d44f 89745:708856d4c65b
1 # cp932.awk -- Add sort key at the tail of each line of CP932-2BYTE.map.
2 # Copyright (C) 2004
3 # National Institute of Advanced Industrial Science and Technology (AIST)
4 # Registration Number H13PRO009
5 #
6 # This file is part of GNU Emacs.
7 #
8 # GNU Emacs is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # GNU Emacs is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Emacs; see the file COPYING. If not, write to the
20 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 # Boston, MA 02111-1307, USA.
22
23 # Comment:
24 # Add a sort key 0, 1, 2, or 3 at the tail of each line as a comment
25 # to realize the round trip mapping to Unicode works as described in
26 # this page:
27 # http://support.microsoft.com/default.aspx?scid=kb;EN-US;170559
28 # Each sort key means as below:
29 # 0: JISX0208 characters.
30 # 1: NEC special characters.
31 # 2: IBM extension characters.
32 # 3: NEC selection of IBM extension characters.
33
34 BEGIN {
35 tohex["A"] = 10;
36 tohex["B"] = 11;
37 tohex["C"] = 12;
38 tohex["D"] = 13;
39 tohex["E"] = 14;
40 tohex["F"] = 15;
41 }
42
43 function decode_hex(str) {
44 n = 0;
45 len = length(str);
46 for (i = 1; i <= len; i++)
47 {
48 c = substr(str, i, 1);
49 if (c >= "0" && c <= "9")
50 n = n * 16 + (c - "0");
51 else
52 n = n * 16 + tohex[c];
53 }
54 return n;
55 }
56
57 function sjis_to_jis_ku(code)
58 {
59 s1 = int(code / 256);
60 s2 = code % 256;
61 if (s2 >= 159) # s2 >= 0x9F
62 {
63 if (s1 >= 224) # s1 >= 0xE0
64 j1 = s1 * 2 - 352; # j1 = s1 * 2 - 0x160
65 else
66 j1 = s1 * 2 - 224; # j1 = s1 * 2 - 0xE0
67 }
68 else
69 {
70 if (s1 >= 224)
71 j1 = s1 * 2 - 353; # j1 = s1 * 2 - 0x161
72 else
73 j1 = s1 * 2 - 225; # j1 = s1 * 2 - 0xE1
74 }
75 return j1 - 32;
76 }
77
78 /^0x[89E]/ {
79 sjis=decode_hex(substr($1, 3, 4))
80 ku=sjis_to_jis_ku(sjis);
81 if (ku == 13)
82 print $0" # 1";
83 else if (ku >= 89 && ku <= 92)
84 print $0" # 3";
85 else
86 print $0" # 0";
87 next;
88 }
89
90 /^0xF/ {
91 print $0" # 2";
92 next;
93 }
94
95 {
96 print;
97 }