Debian Codegraph @

gendata/gen-cjkc

raw
1 #!perl
2 # gen-cjkc : auxiliary script for CJK compatibility ideographs
3 #
4 # input files
5 #
6 # ../Collate/allkeys.txt
7 #
8 # output files
9 #
10 # loc_cjkc.t (equal to t/loc_cjkc.t)
11 #
12 use strict;
13 use warnings;
14 use File::Spec;
15
16 require './gen-head'; # for testcount(), testhead() and testnew()
17 require './dumpstr'; # for string()
18
19 my @obj = qw($objDefault $objB $objG $objJ $objK $objP $objS $objZ);
20 my $ok = 1 + @obj;
21 my $listobj = join ', ', @obj;
22 my $test = <<"TEST";
23 for my \$obj ($listobj) {
24 \$obj->change(level => 3);
25 TEST
26 my $d = File::Spec->updir();
27 my $f = File::Spec->catfile($d, 'Collate', 'allkeys.txt');
28 open my $fh, "<$f" or die $f;
29
30 while (<$fh>) {
31 next if !/\[\.F[0-9A-F]+\.[0-9A-F]+\.0002[\.\]]/;
32 my @p = map hex($_), /\[\.([0-9A-F]+)\./g;
33 next if @p != 2;
34 my $u = ((($p[0] & 0x3F) << 15) | ($p[1] & 0x7FFF));
35 my $c = /^\s*([0-9A-F]+)\s*;/ ? hex($1) : 0;
36 next if $u == $c; # not decomposable
37 my $su = string(pack 'U', $u);
38 my $sc = string(pack 'U', $c);
39 $test .= ' ' x 4 . qq|ok(\$obj->eq($su, $sc));\n|;
40 }
41 close $fh;
42
43 $test .= "}\n";
44
45 testcount(\$ok, $test, 0+@obj);
46 # discard the return value
47
48 my $testf = "loc_cjkc.t";
49 open my $th, ">$testf" or die $testf;
50 binmode $th;
51 print $th testhead('default', $ok);
52 print $th testnew('B', 'ZH__big5han');
53 print $th testnew('G', 'ZH__gb2312han');
54 print $th testnew('J', 'JA');
55 print $th testnew('K', 'KO');
56 print $th testnew('P', 'ZH__pinyin');
57 print $th testnew('S', 'ZH__stroke');
58 print $th testnew('Z', 'ZH__zhuyin');
59 print $th $test;
60 close $th;