| 1 |
#!perl |
| 2 |
# gen-vi : auxiliary script for Vietnamese |
| 3 |
# |
| 4 |
# output files |
| 5 |
# |
| 6 |
# vi.txt (a main part of data/vi.txt) |
| 7 |
# loc_vi.t (a main part of t/loc_vi.t) |
| 8 |
# |
| 9 |
use strict; |
| 10 |
use warnings; |
| 11 |
require './gen-head'; # for testcount() and testhead() |
| 12 |
|
| 13 |
use Unicode::Normalize; |
| 14 |
require './dumpstr'; # for element(), string() and unidump() |
| 15 |
|
| 16 |
my @base = qw( 61 41 103 102 E2 C2 65 45 EA CA 69 49 6F 4F |
| 17 |
F4 D4 1A1 1A0 75 55 1B0 1AF 79 59 ); |
| 18 |
my @tone = qw( 300 340 309 303 301 341 323 ); |
| 19 |
|
| 20 |
my $textf = 'vi.txt'; |
| 21 |
my $text1 = "#equivalent sequences\n"; |
| 22 |
my $text2 = ''; |
| 23 |
my $testf = 'loc_vi.t'; |
| 24 |
my $test0 = ''; |
| 25 |
my $test1 = ''; |
| 26 |
my $test2 = ''; |
| 27 |
my $test3 = ''; |
| 28 |
|
| 29 |
my %data; |
| 30 |
|
| 31 |
for my $b (@base) { |
| 32 |
my $bc = pack 'U', hex $b; |
| 33 |
for my $t (@tone) { |
| 34 |
my $tc = pack 'U', hex $t; |
| 35 |
my $cat = $bc.$tc; |
| 36 |
my $com = NFC($bc.$tc); |
| 37 |
my $dec = NFD($bc).$tc; |
| 38 |
|
| 39 |
my $scat = string($cat); |
| 40 |
my $scom = string($com); |
| 41 |
my $sdec = string($dec); |
| 42 |
$test0 .= qq|ok(\$objVi->eq($sdec, $scom));\n|; |
| 43 |
|
| 44 |
next if length $dec < 3; |
| 45 |
$test3 .= qq|ok(\$objVi->eq($sdec, $scat));\n|; |
| 46 |
|
| 47 |
my @d = split //, $dec; |
| 48 |
my $rule = sprintf "<%s><%s>", unidump($bc), unidump($tc); |
| 49 |
|
| 50 |
my $rv2 = NFC($d[0].$d[2]).$d[1]; |
| 51 |
if ($com eq NFC $rv2) { |
| 52 |
my $srv2 = string($rv2); |
| 53 |
$test1 .= qq|ok(\$objVi->eq($sdec, $srv2));\n|; |
| 54 |
my $d = element($rv2); |
| 55 |
$text1 .= "$d;$rule\n" unless $data{$d}++; |
| 56 |
} |
| 57 |
|
| 58 |
my $rev = $d[0].$d[2].$d[1]; |
| 59 |
if ($com eq NFC $rev) { |
| 60 |
my $srev = string($rev); |
| 61 |
$test2 .= qq|ok(\$objVi->eq($sdec, $srev));\n|; |
| 62 |
my $d = element($rev); |
| 63 |
$text2 .= "$d;$rule\n" unless $data{$d}++; |
| 64 |
} |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
### WRITE DATA ### |
| 69 |
open my $dh, ">$textf" or die $textf; |
| 70 |
binmode $dh; |
| 71 |
print $dh "$text1$text2"; |
| 72 |
close $dh or die $textf; |
| 73 |
|
| 74 |
### WRITE TEST ### |
| 75 |
my $test = ''; |
| 76 |
my $ok = 0; |
| 77 |
|
| 78 |
$test .= testcount(\$ok, 74); |
| 79 |
$test .= testcount(\$ok, $test0); |
| 80 |
$test .= testcount(\$ok, $test1); |
| 81 |
$test .= testcount(\$ok, $test2); |
| 82 |
$test .= testcount(\$ok, $test3); |
| 83 |
$test .= testcount(\$ok, 26); |
| 84 |
|
| 85 |
chomp $test; |
| 86 |
open my $th, ">$testf" or die $testf; |
| 87 |
binmode $th; |
| 88 |
print $th testhead('vi', $ok), $test; |
| 89 |
close $th or die $testf; |