completion--replace: Fix completion cycling
[emacs.git] / admin / charsets / cp932.awk
blob27fdf0214887c1f0c2721592021ea91880dda8c4
1 # cp932.awk -- Add sort keys and append user defined area to CP932-2BYTE.map.
2 # Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
3 # National Institute of Advanced Industrial Science and Technology (AIST)
4 # Registration Number H13PRO009
6 # This file is part of GNU Emacs.
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 3 of the License, or
11 # (at your option) any later version.
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.
18 # You should have received a copy of the GNU General Public License
19 # along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>.
21 # Commentary:
23 # Add a sort key 0, 1, 2, or 3 at the tail of each line as a comment
24 # to realize the round trip mapping to Unicode works as described in
25 # https://www.unicode.org/Public/MAPPINGS/VENDORS/MICSFT/WINDOWS/CP932.TXT
26 # Each sort key means as below:
27 # 0: JISX0208 characters.
28 # 1: NEC special characters.
29 # 2: IBM extension characters.
30 # 3: NEC selection of IBM extension characters.
31 # 4: user defined area
33 BEGIN {
34 tohex["A"] = 10;
35 tohex["B"] = 11;
36 tohex["C"] = 12;
37 tohex["D"] = 13;
38 tohex["E"] = 14;
39 tohex["F"] = 15;
42 function decode_hex(str) {
43 n = 0;
44 len = length(str);
45 for (i = 1; i <= len; i++)
47 c = substr(str, i, 1);
48 if (c >= "0" && c <= "9")
49 n = n * 16 + (c - "0");
50 else
51 n = n * 16 + tohex[c];
53 return n;
56 function sjis_to_jis_ku(code)
58 s1 = int(code / 256);
59 s2 = code % 256;
60 if (s2 >= 159) # s2 >= 0x9F
62 if (s1 >= 224) # s1 >= 0xE0
63 j1 = s1 * 2 - 352; # j1 = s1 * 2 - 0x160
64 else
65 j1 = s1 * 2 - 224; # j1 = s1 * 2 - 0xE0
66 j2 = s2 - 126 # j2 = s2 - #x7E
68 else
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 if (s2 >= 127) # s2 >= #x7F
75 j2 = s2 - 32;
76 else
77 j2 = s2 - 31;
79 return j1 - 32;
82 /^0x[89E]/ {
83 sjis=decode_hex(substr($1, 3, 4))
84 ku=sjis_to_jis_ku(sjis);
85 if (ku == 13)
86 printf "%s # 1 %02X%02X\n", $0, j1, j2;
87 else if (ku >= 89 && ku <= 92)
88 printf "%s # 3 %02X%02X\n", $0, j1, j2;
89 else
90 printf "%s # 0 %02X%02X\n", $0, j1, j2;
91 next;
94 /^0xF/ {
95 printf "%s # 2\n", $0;
96 next;
100 print;
103 END {
104 code = 57344; # 0xE000
105 for (i = 240; i < 250; i++)
107 for (j = 64; j <= 126; j++)
108 printf "0x%02X%02X 0x%04X # 4\n", i, j, code++;
109 for (j = 128; j <= 158; j++)
110 printf "0x%02X%02X 0x%04X # 4\n", i, j, code++;
111 for (; j <= 252; j++)
112 printf "0x%02X%02X 0x%04X # 4\n", i, j, code++;