aboutsummaryrefslogtreecommitdiffstats
path: root/libwc/map/mk_jis_ucs_map.pl
blob: dea7d92a9d5c34e447b70549b488c28c2d8c2b12 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
@NAME = ();
while(<DATA>) {
  chop;
  s/\s*$//;
  (($n, $m, $c) = split(" ", $_, 3)) >= 3 || next;
  push(@NAME, $n);
  $MAP{$n} = $m;
  $CODE{$n} = $c;
}

$name0 = "jisx0208x0212x0213";
# print OUT <<EOF;
# /*
#   These conversion tables between $code and
#   Unicode were made from
# 
#     ftp://ftp.unicode.org/Public/MAPPINGS/$MAP{$NAME[0]},
#     ftp://ftp.unicode.org/Public/MAPPINGS/$MAP{$NAME[1]}.
# 
# */
# EOF
# Unicode(CP932)				Unicode(JIS X 0208)
%from_ucs = (
  0x00A5, 0x216F, # YEN SIGN
  0x00B5, 0x264C, # MICRO SIGN
  0xFF3C, 0x2140, # FULLWIDTH REVERSE SOLIDUS	0x005C REVERSE SOLIDUS
  0xFF5E, 0x2141, # FULLWIDTH TILDE		0x301C WAVE DASH
  0x2225, 0x2142, # PARALLEL TO			0x2016 DOUBLE VERTICAL LINE
  0xFF0D, 0x215D, # FULLWIDTH HYPHEN-MINUS	0x2212 MINUS SIGN
  0xFFE0, 0x2171, # FULLWIDTH CENT SIGN		0x00A2 CENT SIGN
  0xFFE1, 0x2172, # FULLWIDTH POUND SIGN	0x00A3 POUND SIGN
  0xFFE2, 0x224C, # FULLWIDTH NOT SIGN		0x00AC NOT SIGN
);
for(keys %from_ucs) {
  ($_ == 0x00A5) && next;
  ($_ == 0x00B5) && next;
  $to_ucs[$from_ucs{$_}] = $_;
}

open(OUT, "> ${name0}_ucs.map");
foreach $name (@NAME) {

$code = $CODE{$name};
$map = $MAP{$name};

print "$name\t$map\t$code\n";

open(MAP, "< $map");
while(<MAP>) {
  /^#/ && next;
  s/#.*//;
  if ($name =~ /0208/) {
    (($s, $i, $u) = split(" ")) || next;
    $i = hex($i);
    $u = hex($u);
    if ($u == 0x5C) {
	$u = 0xFF3C;
    }
    $to_ucs[$i] || ($to_ucs[$i] = $u);
    $to_ucs_jis[$i] = 0;
    $from_ucs{$u} = $i;
  } elsif ($name =~ /0212/) {
    (($i, $u) = split(" ")) || next;
    $i = hex($i);
    $u = hex($u);
    if ($u == 0x7E) {
	$u = 0xFF5E;
    }
    $to_ucs2[$i] = $u;
    $to_ucs2_jis[$i] = 0;
    $from_ucs2{$u} = $i;
  } else {
    /^\d/ || next;
    (($p,$i,$e,$s,$u) = split(" ")) || next;
    $i =~ s/j-/0x/;
    $u =~ s/u-/0x/;
    $i = hex($i);
    $u = hex($u);
    if ($u == 0xffff) {
	$u = 0;
    }
    if ($u == 0x7E) {
	$u = 0xFF5E;
    }
    if ($p =~ /^1/) {
      $to_ucs[$i] && next;
      $to_ucs[$i] = $u;
      $to_ucs_jis[$i] = 1;
      $from_ucs3{$u} = $i;
    } elsif ($p =~ /^2/) {
      $to_ucs2[$i] = $u;
      $to_ucs2_jis[$i] = 1;
      $from_ucs4{$u} = $i;
    }
  }
}

}

print OUT <<EOF;
/* JIS X 0208, JIS X 0212, JIS X 0213 (Japanese) */

static wc_uint16 jisx0208x02131_ucs_map[ 0x5E * 0x5E ] = {
EOF

for $i (0x21 .. 0x7E) {
for $j (0x21 .. 0x7E) {
  $_ = $i * 0x100 + $j;
  $u = $to_ucs[$_];
  if ($u) {
    printf OUT " 0x%.4X,", $u;
  } else {
    print OUT " 0,\t";
  }
  printf OUT "\t/* %s 0x%.4X */\n", $to_ucs_jis[$_] ? "JIS X 0213-1" : "JIS X 0208", $_;
}
}

print OUT <<EOF;
};

static wc_uint16 jisx0212x02132_ucs_map[ 0x5E * 0x5E ] = {
EOF

for $i (0x21 .. 0x7E) {
for $j (0x21 .. 0x7E) {
  $_ = $i * 0x100 + $j;
  $u = $to_ucs2[$_];
  if ($u) {
    printf OUT " 0x%.4X,", $u;
  } else {
    print OUT " 0,\t";
  }
  printf OUT "\t/* %s 0x%.4X */\n", $to_ucs2_jis[$_] ? "JIS X 0213-2" : "JIS X 0212", $_;
}
}

print OUT <<EOF;
};
EOF

@ucs = sort { $a <=> $b } keys %from_ucs;
$nucs = @ucs + 0;

print OUT <<EOF;

#define N_ucs_jisx0208_map $nucs

static wc_map ucs_jisx0208_map[ N_ucs_jisx0208_map ] = {
EOF
for(@ucs) {
  $_ || next;
  printf OUT "  { 0x%.4X, 0x%.4X },\n", $_, $from_ucs{$_};
}

@ucs = sort { $a <=> $b } keys %from_ucs2;
$nucs = @ucs + 0;

print OUT <<EOF;
};

#define N_ucs_jisx0212_map $nucs

static wc_map ucs_jisx0212_map[ N_ucs_jisx0212_map ] = {
EOF
for(@ucs) {
  $_ || next;
  printf OUT "  { 0x%.4X, 0x%.4X },\n", $_, $from_ucs2{$_};
}

@ucs = sort { $a <=> $b } keys %from_ucs3;
$nucs = @ucs + 0;

print OUT <<EOF;
};

#define N_ucs_jisx02131_map $nucs

static wc_map ucs_jisx02131_map[ N_ucs_jisx02131_map ] = {
EOF
for(@ucs) {
  $_ || next;
  printf OUT "  { 0x%.4X, 0x%.4X },\n", $_, $from_ucs3{$_};
}

@ucs = sort { $a <=> $b } keys %from_ucs4;
$nucs = @ucs + 0;

print OUT <<EOF;
};

#define N_ucs_jisx02132_map $nucs

static wc_map ucs_jisx02132_map[ N_ucs_jisx02132_map ] = {
EOF
for(@ucs) {
  $_ || next;
  printf OUT "  { 0x%.4X, 0x%.4X },\n", $_, $from_ucs4{$_};
}

print OUT <<EOF;
};
EOF

close(MAP);

__END__
jisx0208	EASTASIA/JIS/JIS0208.TXT	JIS X 0208 (Japanese)
jisx0212	EASTASIA/JIS/JIS0212.TXT	JIS X 0212 (Japanese)
jisx0213	jisx0213code.txt		JIS X 0213 (Japanese)