mk_ks_ucs_map.pl (1321B)
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 @to_ucs = (); 20 %from_ucs = (); 21 open(MAP, "< $map"); 22 open(OUT, "> ${name}_ucs.map"); 23 while(<MAP>) { 24 /^#/ && next; 25 s/#.*//; 26 (($i, $u) = split(" ")) || next; 27 $i = hex($i); 28 $u = hex($u); 29 $to_ucs[$i] = $u; 30 if ($u > 0) { 31 $from_ucs{$u} = $i; 32 } 33 } 34 35 # print OUT <<EOF; 36 # /* 37 # These conversion tables between $code and 38 # Unicode were made from 39 # 40 # ftp://ftp.unicode.org/Public/MAPPINGS/$map. 41 # */ 42 print OUT <<EOF; 43 /* $code */ 44 45 static wc_uint16 ${name}_ucs_map[ 0x5E * 0x5E ] = { 46 EOF 47 48 for $i (0x21 .. 0x7E) { 49 for $j (0x21 .. 0x7E) { 50 $_ = $i * 0x100 + $j; 51 $u = $to_ucs[$_]; 52 if ($u) { 53 printf OUT " 0x%.4X,", $u; 54 } else { 55 print OUT " 0,\t"; 56 } 57 printf OUT "\t/* 0x%.4X */\n", $_; 58 } 59 } 60 61 @ucs = sort { $a <=> $b } keys %from_ucs; 62 $nucs = @ucs + 0; 63 64 print OUT <<EOF; 65 }; 66 67 #define N_ucs_${name}_map $nucs 68 69 static wc_map ucs_${name}_map[ N_ucs_${name}_map ] = { 70 EOF 71 for(@ucs) { 72 printf OUT " { 0x%.4X, 0x%.4X },\n", $_, $from_ucs{$_}; 73 } 74 75 print OUT <<EOF; 76 }; 77 EOF 78 79 close(MAP); 80 } 81 82 __END__ 83 ksx1001 EASTASIA/KSC/KSX1001.TXT KS X 1001 (Korean)