mk_jisx0213_ucs_map.pl (1839B)
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 foreach $name (@NAME) { 13 14 $code = $CODE{$name}; 15 $map = $MAP{$name}; 16 17 print "$name\t$map\t$code\n"; 18 19 open(MAP, "< $map"); 20 while(<MAP>) { 21 /^#/ && next; 22 s/#.*//; 23 (($u, $s, $i) = split(" ")) || next; 24 $u =~ s/^U\+2//; 25 if ($i =~ s/3-//) { 26 $i = hex($i); 27 $u = hex($u); 28 $to_ucs1{$i} = $u; 29 $from_ucs1{$u} = $i; 30 } elsif ($i =~ s/4-//) { 31 $i = hex($i); 32 $u = hex($u); 33 $to_ucs2{$i} = $u; 34 $from_ucs2{$u} = $i; 35 } 36 } 37 open(OUT, "> ${name}_ucs.map"); 38 39 @ucs = sort { $a <=> $b } keys %to_ucs1; 40 $nucs = @ucs + 0; 41 print OUT <<EOF; 42 /* $code */ 43 44 #define N_${name}1_ucs_p2_map $nucs 45 46 static wc_map ${name}1_ucs_p2_map[ N_${name}1_ucs_p2_map ] = { 47 EOF 48 for(@ucs) { 49 $_ || next; 50 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $to_ucs1{$_}; 51 } 52 53 @ucs = sort { $a <=> $b } keys %from_ucs1; 54 $nucs = @ucs + 0; 55 print OUT <<EOF; 56 }; 57 58 #define N_ucs_p2_${name}1_map $nucs 59 60 static wc_map ucs_p2_${name}1_map[ N_ucs_p2_${name}1_map ] = { 61 EOF 62 for(@ucs) { 63 $_ || next; 64 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs1{$_}; 65 } 66 67 @ucs = sort { $a <=> $b } keys %to_ucs2; 68 $nucs = @ucs + 0; 69 print OUT <<EOF; 70 }; 71 72 #define N_${name}2_ucs_p2_map $nucs 73 74 static wc_map ${name}2_ucs_p2_map[ N_${name}2_ucs_p2_map ] = { 75 EOF 76 for(@ucs) { 77 $_ || next; 78 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $to_ucs2{$_}; 79 } 80 81 @ucs = sort { $a <=> $b } keys %from_ucs2; 82 $nucs = @ucs + 0; 83 print OUT <<EOF; 84 }; 85 86 #define N_ucs_p2_${name}2_map $nucs 87 88 static wc_map ucs_p2_${name}2_map[ N_ucs_p2_${name}2_map ] = { 89 EOF 90 for(@ucs) { 91 $_ || next; 92 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs2{$_}; 93 } 94 print OUT <<EOF; 95 }; 96 EOF 97 98 close(MAP); 99 close(OUT); 100 } 101 102 __END__ 103 jisx0213 JISX0213.TXT JIS X 0213 (Japanese) 104