mk_hkscs_ucs_map.pl (1305B)
1 2 @NAME = (); 3 while(<DATA>) { 4 chop; 5 s/\s+$//; 6 (($n, $m, $d) = split(" ", $_, 3)) >= 3 || next; 7 push(@NAME, $n); 8 $MAP{$n} = $m; 9 $DESC{$n} = $d; 10 } 11 12 @to_ucs = (); 13 %from_ucs = (); 14 15 foreach $name (@NAME) { 16 17 $map = $MAP{$name}; 18 $desc = $DESC{$name}; 19 print STDERR "$name\t$map\t$desc\n"; 20 21 open(MAP, "< $map"); 22 while(<MAP>) { 23 (($c, $u) = split(" ")) || next; 24 $c = hex($c); 25 $u = hex($u); 26 if (($c < 0xA140 || $c > 0xF9FE) && 27 (($u > 0 && $u < 0xE000) || $u > 0xF8FF)) { 28 $to_ucs[$c] = $u; 29 $from_ucs{$u} = $c; 30 } 31 } 32 close(MAP); 33 34 } 35 36 $name = $NAME[0]; 37 $desc = $DESC{$name}; 38 39 open(OUT, "> ${name}_ucs.map"); 40 41 print OUT <<EOF; 42 /* $desc */ 43 44 static wc_uint16 ${name}_ucs_map[ 0x1E * 0x9D ] = { 45 EOF 46 47 for $i (0x88 .. 0xA0, 0xFA .. 0xFE) { 48 for $j (0x40 .. 0x7E, 0xA1 .. 0xFE) { 49 $_ = $i * 0x100 + $j; 50 $u = $to_ucs[$_]; 51 if ($u) { 52 printf OUT " 0x%.4X,", $u; 53 } else { 54 print OUT " 0,\t"; 55 } 56 printf OUT "\t/* 0x%.4X */\n", $_; 57 } 58 } 59 60 @ucs = sort { $a <=> $b } keys %from_ucs; 61 $nucs = @ucs + 0; 62 63 print OUT <<EOF; 64 }; 65 66 #define N_ucs_${name}_map $nucs 67 /* 68 UCS-2 HKSCS 69 */ 70 static wc_map ucs_${name}_map[ N_ucs_${name}_map ] = { 71 EOF 72 for(@ucs) { 73 $x = $from_ucs{$_}; 74 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $x; 75 } 76 77 print OUT <<EOF; 78 }; 79 EOF 80 81 __END__ 82 hkscs private/hkscs.txt HKSCS (Chinese Hong Kong)