| 1 |
#!perl |
| 2 |
# gen-hu : auxiliary script for Hungarian |
| 3 |
# |
| 4 |
# output files |
| 5 |
# |
| 6 |
# hu.txt (equal to data/hu.txt) |
| 7 |
# loc_hu.t (a main part of t/loc_hu.t) |
| 8 |
# |
| 9 |
use strict; |
| 10 |
use warnings; |
| 11 |
require './gen-head'; # for testcount() and testhead() |
| 12 |
|
| 13 |
my @a = qw( cs dz dzs gy ly ny sz ty zs ); |
| 14 |
|
| 15 |
my $textf = 'hu.txt'; |
| 16 |
my $text1 = ''; |
| 17 |
my $text2 = "00F6;o+1\n00D6;O+1\n0151;o+1++1\n0150;O+1++1\n" |
| 18 |
. "00FC;u+1\n00DC;U+1\n0171;u+1++1\n0170;U+1++1\n" |
| 19 |
. "#here ccs is identical to cscs etc.\n"; |
| 20 |
my $testf = 'loc_hu.t'; |
| 21 |
my $test1 = ''; |
| 22 |
my $test2 = ''; |
| 23 |
|
| 24 |
for my $e (@a) { |
| 25 |
my @c = split //, $e; |
| 26 |
my $u1 = uc $c[0]; |
| 27 |
my $l1 = lc $c[0]; |
| 28 |
my $u2 = uc $c[1]; |
| 29 |
my $l2 = lc $c[1]; |
| 30 |
my @set; |
| 31 |
if (@c == 2) { |
| 32 |
@set = map { ($_ & 2 ? $u1 : $l1).($_ & 1 ? $u2 : $l2) } (0..3); |
| 33 |
} else { |
| 34 |
my $u3 = uc $c[2]; |
| 35 |
my $l3 = lc $c[2]; |
| 36 |
@set = map { ($_ & 4 ? $u1 : $l1).($_ & 2 ? $u2 : $l2) |
| 37 |
.($_ & 1 ? $u3 : $l3) } (0..7); |
| 38 |
} |
| 39 |
|
| 40 |
my $set = @set; |
| 41 |
my $s_1 = $set - 1; |
| 42 |
my $max = 2 * $set -1; |
| 43 |
my @third = (8,2,7); |
| 44 |
for my $i (0..$s_1) { |
| 45 |
$text1 .= "{" . $set[$i] . "};"; |
| 46 |
$text1 .= ($i ? $u1 : $l1). "+" .(@c == 2 ? 1 : 2); |
| 47 |
if ($i != 0 && $i != $s_1) { |
| 48 |
$text1 .= "---1 "; |
| 49 |
$text1 .= sprintf "[.0.0.%d.0]", $third[$i < $set/2]; |
| 50 |
$text1 .= sprintf "[.0.0.%d.0]", $third[$i % 3] if @c == 3; |
| 51 |
} |
| 52 |
$text1 .= "\n"; |
| 53 |
} |
| 54 |
for my $i (0..$max) { |
| 55 |
my $f = $i & $set ? $u1 : $l1; |
| 56 |
my $left = $f. $set[$i & $s_1]; |
| 57 |
my $r1 = $set[$i & $set ? $s_1 : 0]; |
| 58 |
my $r2 = $set[$i & $s_1]; |
| 59 |
|
| 60 |
$text2 .= "{$left};<{$r1}><{$r2}>\n"; |
| 61 |
$test2 .= qq|ok(\$objHu->eq("$left", "$r1$r2"));\n|; |
| 62 |
} |
| 63 |
for my $i (1..$s_1) { |
| 64 |
$test1 .= qq|ok(\$objHu->eq("$set[$i-1]", "$set[$i]"));\n|; |
| 65 |
} |
| 66 |
} |
| 67 |
|
| 68 |
|
| 69 |
### WRITE DATA ### |
| 70 |
open my $dh, ">$textf" or die $textf; |
| 71 |
binmode $dh; |
| 72 |
print $dh "$text1$text2"; |
| 73 |
close $dh or die $textf; |
| 74 |
|
| 75 |
### WRITE TEST ### |
| 76 |
my $test = ''; |
| 77 |
my $ok = 0; |
| 78 |
|
| 79 |
$test .= "\$objHu->change(level => 1);\n\n"; |
| 80 |
$test .= testcount(\$ok, 34); |
| 81 |
|
| 82 |
$test .= "\$objHu->change(level => 2);\n\n"; |
| 83 |
$test .= testcount(\$ok, $test1); |
| 84 |
$test .= testcount(\$ok, 6); |
| 85 |
|
| 86 |
$test1 =~ s/->eq/->lt/g; |
| 87 |
$test .= "\$objHu->change(level => 3);\n\n"; |
| 88 |
$test .= testcount(\$ok, $test1); |
| 89 |
$test .= testcount(\$ok, 22); |
| 90 |
$test .= testcount(\$ok, $test2); |
| 91 |
|
| 92 |
$test1 =~ s/->lt/->gt/g; |
| 93 |
$test .= "\$objHu->change(upper_before_lower => 1);\n\n"; |
| 94 |
$test .= testcount(\$ok, $test1); |
| 95 |
|
| 96 |
chomp $test; |
| 97 |
open my $th, ">$testf" or die $testf; |
| 98 |
binmode $th; |
| 99 |
print $th testhead('hu', $ok), $test; |
| 100 |
close $th or die $testf; |