1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
#! /usr/bin/perl -w -CDSL
# fileformat documentation: JOSM I18n.java function load()
use Term::ReadKey;
use strict;
use utf8;
use Encode;
my $tlen = (GetTerminalSize())[0]-11;
my $data;
foreach my $file (@ARGV)
{
if(open FILE,"<:raw",$file)
{
my $miss = 0;
my $missm = 0;
my $i = 1;
my $num = 0;
for(;;)
{
read FILE,$data,2;
my $len = unpack("n",$data);
last if $len == 65535;
if($len == 65534)
{
printf("%4d +++++\n", $i);
++$num;
}
elsif($len)
{
++$num;
read FILE,$data,$len;
$data = decode("utf-8", $data);
$data =~ s/\r/\\r/g;
$data =~ s/\n/\\n/g;
$data = substr($data, 0, $tlen);
printf("%4d %5d %s\n", $i, $len, $data);
}
else
{
printf("%4d -----\n", $i);
++$miss;
}
++$i;
}
my $mul = 0;
my $tot = 0;
my $max = 0;
my $comp = 0;
print "multi:\n";
$i = 1;
for(;;)
{
last if !read FILE,$data,1;
my $cnt = unpack("C",$data);
++$mul if $cnt;
if($cnt == 0xFE)
{
++$comp;
$tot += 2;
$cnt = 0;
printf("%4d +++++\n",$i);
}
else
{
if($cnt > $max)
{
$comp = 0;
$max = $cnt;
}
++$comp if $cnt == $max;
$tot += $cnt;
printf("%4d -----\n",$i) if(!$cnt);
}
while($cnt--)
{
read FILE,$data,2;
my $len = unpack("n",$data);
if($len)
{
read FILE,$data,$len;
$data = decode("utf-8", $data);
$data =~ s/\r/\\r/g;
$data =~ s/\n/\\n/g;
$data = substr($data, 0, $tlen);
printf("%4d %5d %s\n", $i, $len, $data);
}
else
{
++$missm;
}
}
++$i;
}
close FILE;
printf("Status: Missing %d/%d - $num,$mul,$tot,$max,$comp\n",$miss,$missm);
}
else
{
print STDERR "Could not load language file $file.\n";
}
}
|