check_links.pl 1.07 KB
Newer Older
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
#!/usr/bin/perl

sub catfile {
    my $a = "";
    open(F, shift) || return "";
    while (<F>) { s/\r//g; trim; if (not m/^#/) { $a .= $_; } };
    close(F);
    return $a;
}

$original = "english";
$translation = "german";
$origfile = "links.en.txt";
$transfile = "links.de.txt";

open FR, ">$transfile" || die "Can't create file";
open FE, ">$origfile" || die "Can't create file";

@list = `find $translation/ -name *.wml -type f -print`;

foreach $rus (@list) {
    chomp($rus);
    ($eng = $rus) =~ s{$translation}{$original};
    ($f = $rus) =~ s{$translation/}{};

    $rrus = catfile($rus);
    $rrus =~ s{/\n}{}g;
    $rrus =~ s{\n}{ }g;
    @lrus = ();
    $rrus =~ s{<[aA]\s*[hH][rR][eE][fF]=(.*?)>}{
	push @lrus, "$f: $1"; $1
    }gse;
    foreach (sort @lrus) { print FR "$_\n"; }

    $reng = catfile($eng);
    $reng =~ s{/\n}{}g;
    $reng =~ s{\n}{ }g;
    @leng = ();
    $reng =~ s{<[aA]\s*[hH][rR][eE][fF]=(.*?)>}{
	push @leng, "$f: $1"; $1
    }gse;
    foreach (sort @leng) { print FE "$_\n"; }
}

close FE;
close FR;

exec("diff -u $transfile $origfile > links.diff");