Debian Codegraph @

libwc/map/mk_cns_ucs_map.pl

raw
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_ucs1 = ();
20 @to_ucs2 = ();
21 %from_ucs = ();
22 open(MAP, "< $map");
23 open(OUT, "> ${name}_ucs.map");
24 while(<MAP>) {
25 /^#/ && next;
26 s/#.*//;
27 (($i, $u) = split(" ")) || next;
28 $i =~ s/0x(.)/0x/;
29 $p = $1;
30 $i = hex($i);
31 $u = hex($u);
32 if ($p == 1) {
33 $to_ucs1[$i] = $u;
34 $from_ucs{$u} = $i;
35 } elsif ($p == 2) {
36 $to_ucs2[$i] = $u;
37 $from_ucs{$u} = $i + 0x8000;
38 }
39 }
40
41 # print OUT <<EOF;
42 # /*
43 # These conversion tables between $code and
44 # Unicode were made from
45 #
46 # ftp://ftp.unicode.org/Public/MAPPINGS/$map.
47 # */
48 print OUT <<EOF;
49 /* $code */
50
51 static wc_uint16 ${name}1_ucs_map[ 0x5E * 0x5E ] = {
52 EOF
53
54 for $i (0x21 .. 0x7E) {
55 for $j (0x21 .. 0x7E) {
56 $_ = $i * 0x100 + $j;
57 $u = $to_ucs1[$_];
58 if ($u) {
59 printf OUT " 0x%.4X,", $u;
60 } else {
61 print OUT " 0,\t";
62 }
63 printf OUT "\t/* 0x%.4X */\n", $_;
64 }
65 }
66
67 print OUT <<EOF;
68 };
69
70 static wc_uint16 ${name}2_ucs_map[ 0x5E * 0x5E ] = {
71 EOF
72
73 for $i (0x21 .. 0x7E) {
74 for $j (0x21 .. 0x7E) {
75 $_ = $i * 0x100 + $j;
76 $u = $to_ucs2[$_];
77 if ($u) {
78 printf OUT " 0x%.4X,", $u;
79 } else {
80 print OUT " 0,\t";
81 }
82 printf OUT "\t/* 0x%.4X */\n", $_;
83 }
84 }
85
86 @ucs = sort { $a <=> $b } keys %from_ucs;
87 $nucs = @ucs + 0;
88
89 print OUT <<EOF;
90 };
91
92 #define N_ucs_${name}_map $nucs
93 /*
94 UCS-2 CNS 11643-1
95 UCS-2 CNS 11643-2 | 0x8000
96 */
97 static wc_map ucs_${name}_map[ N_ucs_${name}_map ] = {
98 EOF
99 for(@ucs) {
100 printf OUT " { 0x%.4X, 0x%.4X },", $_, $from_ucs{$_};
101 if ($from_ucs{$_} & 0x8000) {
102 print OUT "\t/* CNS 11643-2 */\n";
103 } else {
104 print OUT "\t/* CNS 11643-1 */\n";
105 }
106 }
107
108 print OUT <<EOF;
109 };
110 EOF
111
112 close(MAP);
113 }
114
115 __END__
116 cns11643 EASTASIA/OTHER/CNS11643.TXT CNS 11643 (Chinese Taiwan)