From 5f8e0f8ef9a422691dd72e8a953a42a41478fcb4 Mon Sep 17 00:00:00 2001 From: Tatsuya Kinoshita Date: Wed, 4 May 2011 16:18:09 +0900 Subject: Releasing debian version 0.5.1-1 --- libwc/map/mk_gb18030_ucs_map.pl | 172 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 172 insertions(+) create mode 100644 libwc/map/mk_gb18030_ucs_map.pl (limited to 'libwc/map/mk_gb18030_ucs_map.pl') diff --git a/libwc/map/mk_gb18030_ucs_map.pl b/libwc/map/mk_gb18030_ucs_map.pl new file mode 100644 index 0000000..a5ba29b --- /dev/null +++ b/libwc/map/mk_gb18030_ucs_map.pl @@ -0,0 +1,172 @@ + +@NAME = (); +while() { + chop; + s/\s*$//; + (($n, $m, $c) = split(" ", $_, 3)) >= 3 || next; + push(@NAME, $n); + $MAP{$n} = $m; + $CODE{$n} = $c; +} + +%from_ucs0 = (); +foreach $name (@NAME) { + +$code = $CODE{$name}; +$map = $MAP{$name}; + +print "$name\t$map\t$code\n"; + +%to_ucs = (); +%from_ucs = (); +open(MAP, "< $map"); +while() { + /^#/ && next; + s/#.*//; + (($i, $u) = split(" ")) || next; + $i = hex($i); + $u = hex($u); + $from_ucs{$u} = $i; + if (! $from_ucs0{$u}) { + $to_ucs{$i} = $u; + } +} + +if ($name eq "gbk") { + %from_ucs0 = %from_ucs; + next; +} + +$p = 0; +for $ub (0x81 .. 0xFE) { + for $lb (0x40 .. 0x7E, 0x80 .. 0xFE) { + $i = ($ub << 8) + $lb; + if ($u = $to_ucs{$i}) { + if ($u != $ou + 1) { + if ($p) { + $ucs2_end{$su} = $ou; + $gbk_end{$s} = $og; + } + $p = 0; + } + if (! $p) { + $to_ucs2{$i} = $u; + $from_ucs2{$u} = $i; + $s = $i; + $su = $u; + } + $p = 1; + $ou = $u; + } else { + if ($p) { + $ucs2_end{$su} = $ou; + $gbk_end{$s} = $og; + } + $p = 0; + } + $og = $i; + } +} +if ($p) { + $ucs2_end{$su} = $ou; + $gbk_end{$s} = 0xFEFE; +} + +%from_ucs4 = (); +$i = 0; +$p = 0; +for $u (0x0080 .. 0xD7FF, 0xE000 .. 0xFFFF) { + if (! $from_ucs{$u}) { + if (! $p) { + $from_ucs4{$u} = $i; + $s = $u; + } + $i++; + $p = 1; + } else { + if ($p) { + $ucs4_end{$s} = $u - 1; + } + $p = 0; + } + if ($u == 0xD7FF) { + if ($p) { + $ucs4_end{$s} = $u - 1; + } + $p = 0; + } +} +if ($p) { + $ucs4_end{$s} = 0xFFFF; +} + +open(OUT, "> ${name}_ucs.map"); + +# print OUT < $b } keys %to_ucs2; +$nucs = @ucs + 0; + +print OUT < $b } keys %from_ucs2; +$nucs = @ucs + 0; + +print OUT < $b } keys %from_ucs4; +$nucs = @ucs + 0; + +print OUT <