mk_jis_ucs_map.pl (4251B)
1 2 @NAME = (); 3 while(<DATA>) { 4 chop; 5 s/\s*$//; 6 (($n, $m, $c) = split(" ", $_, 3)) >= 3 || next; 7 push(@NAME, $n); 8 $MAP{$n} = $m; 9 $CODE{$n} = $c; 10 } 11 12 $name0 = "jisx0208x0212x0213"; 13 # print OUT <<EOF; 14 # /* 15 # These conversion tables between $code and 16 # Unicode were made from 17 # 18 # ftp://ftp.unicode.org/Public/MAPPINGS/$MAP{$NAME[0]}, 19 # ftp://ftp.unicode.org/Public/MAPPINGS/$MAP{$NAME[1]}. 20 # 21 # */ 22 # EOF 23 # Unicode(CP932) Unicode(JIS X 0208) 24 %from_ucs = ( 25 0x00A5, 0x216F, # YEN SIGN 26 0x00B5, 0x264C, # MICRO SIGN 27 0xFF3C, 0x2140, # FULLWIDTH REVERSE SOLIDUS 0x005C REVERSE SOLIDUS 28 0xFF5E, 0x2141, # FULLWIDTH TILDE 0x301C WAVE DASH 29 0x2225, 0x2142, # PARALLEL TO 0x2016 DOUBLE VERTICAL LINE 30 0xFF0D, 0x215D, # FULLWIDTH HYPHEN-MINUS 0x2212 MINUS SIGN 31 0xFFE0, 0x2171, # FULLWIDTH CENT SIGN 0x00A2 CENT SIGN 32 0xFFE1, 0x2172, # FULLWIDTH POUND SIGN 0x00A3 POUND SIGN 33 0xFFE2, 0x224C, # FULLWIDTH NOT SIGN 0x00AC NOT SIGN 34 ); 35 for(keys %from_ucs) { 36 ($_ == 0x00A5) && next; 37 ($_ == 0x00B5) && next; 38 $to_ucs[$from_ucs{$_}] = $_; 39 } 40 41 open(OUT, "> ${name0}_ucs.map"); 42 foreach $name (@NAME) { 43 44 $code = $CODE{$name}; 45 $map = $MAP{$name}; 46 47 print "$name\t$map\t$code\n"; 48 49 open(MAP, "< $map"); 50 while(<MAP>) { 51 /^#/ && next; 52 s/#.*//; 53 if ($name =~ /0208/) { 54 (($s, $i, $u) = split(" ")) || next; 55 $i = hex($i); 56 $u = hex($u); 57 if ($u == 0x5C) { 58 $u = 0xFF3C; 59 } 60 $to_ucs[$i] || ($to_ucs[$i] = $u); 61 $to_ucs_jis[$i] = 0; 62 $from_ucs{$u} = $i; 63 } elsif ($name =~ /0212/) { 64 (($i, $u) = split(" ")) || next; 65 $i = hex($i); 66 $u = hex($u); 67 if ($u == 0x7E) { 68 $u = 0xFF5E; 69 } 70 $to_ucs2[$i] = $u; 71 $to_ucs2_jis[$i] = 0; 72 $from_ucs2{$u} = $i; 73 } else { 74 /^\d/ || next; 75 (($p,$i,$e,$s,$u) = split(" ")) || next; 76 $i =~ s/j-/0x/; 77 $u =~ s/u-/0x/; 78 $i = hex($i); 79 $u = hex($u); 80 if ($u == 0xffff) { 81 $u = 0; 82 } 83 if ($u == 0x7E) { 84 $u = 0xFF5E; 85 } 86 if ($p =~ /^1/) { 87 $to_ucs[$i] && next; 88 $to_ucs[$i] = $u; 89 $to_ucs_jis[$i] = 1; 90 $from_ucs3{$u} = $i; 91 } elsif ($p =~ /^2/) { 92 $to_ucs2[$i] = $u; 93 $to_ucs2_jis[$i] = 1; 94 $from_ucs4{$u} = $i; 95 } 96 } 97 } 98 99 } 100 101 print OUT <<EOF; 102 /* JIS X 0208, JIS X 0212, JIS X 0213 (Japanese) */ 103 104 static wc_uint16 jisx0208x02131_ucs_map[ 0x5E * 0x5E ] = { 105 EOF 106 107 for $i (0x21 .. 0x7E) { 108 for $j (0x21 .. 0x7E) { 109 $_ = $i * 0x100 + $j; 110 $u = $to_ucs[$_]; 111 if ($u) { 112 printf OUT " 0x%.4X,", $u; 113 } else { 114 print OUT " 0,\t"; 115 } 116 printf OUT "\t/* %s 0x%.4X */\n", $to_ucs_jis[$_] ? "JIS X 0213-1" : "JIS X 0208", $_; 117 } 118 } 119 120 print OUT <<EOF; 121 }; 122 123 static wc_uint16 jisx0212x02132_ucs_map[ 0x5E * 0x5E ] = { 124 EOF 125 126 for $i (0x21 .. 0x7E) { 127 for $j (0x21 .. 0x7E) { 128 $_ = $i * 0x100 + $j; 129 $u = $to_ucs2[$_]; 130 if ($u) { 131 printf OUT " 0x%.4X,", $u; 132 } else { 133 print OUT " 0,\t"; 134 } 135 printf OUT "\t/* %s 0x%.4X */\n", $to_ucs2_jis[$_] ? "JIS X 0213-2" : "JIS X 0212", $_; 136 } 137 } 138 139 print OUT <<EOF; 140 }; 141 EOF 142 143 @ucs = sort { $a <=> $b } keys %from_ucs; 144 $nucs = @ucs + 0; 145 146 print OUT <<EOF; 147 148 #define N_ucs_jisx0208_map $nucs 149 150 static wc_map ucs_jisx0208_map[ N_ucs_jisx0208_map ] = { 151 EOF 152 for(@ucs) { 153 $_ || next; 154 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs{$_}; 155 } 156 157 @ucs = sort { $a <=> $b } keys %from_ucs2; 158 $nucs = @ucs + 0; 159 160 print OUT <<EOF; 161 }; 162 163 #define N_ucs_jisx0212_map $nucs 164 165 static wc_map ucs_jisx0212_map[ N_ucs_jisx0212_map ] = { 166 EOF 167 for(@ucs) { 168 $_ || next; 169 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs2{$_}; 170 } 171 172 @ucs = sort { $a <=> $b } keys %from_ucs3; 173 $nucs = @ucs + 0; 174 175 print OUT <<EOF; 176 }; 177 178 #define N_ucs_jisx02131_map $nucs 179 180 static wc_map ucs_jisx02131_map[ N_ucs_jisx02131_map ] = { 181 EOF 182 for(@ucs) { 183 $_ || next; 184 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs3{$_}; 185 } 186 187 @ucs = sort { $a <=> $b } keys %from_ucs4; 188 $nucs = @ucs + 0; 189 190 print OUT <<EOF; 191 }; 192 193 #define N_ucs_jisx02132_map $nucs 194 195 static wc_map ucs_jisx02132_map[ N_ucs_jisx02132_map ] = { 196 EOF 197 for(@ucs) { 198 $_ || next; 199 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs4{$_}; 200 } 201 202 print OUT <<EOF; 203 }; 204 EOF 205 206 close(MAP); 207 208 __END__ 209 jisx0208 EASTASIA/JIS/JIS0208.TXT JIS X 0208 (Japanese) 210 jisx0212 EASTASIA/JIS/JIS0212.TXT JIS X 0212 (Japanese) 211 jisx0213 jisx0213code.txt JIS X 0213 (Japanese) 212