xref: /freebsd/tools/tools/iso/check-iso639.pl (revision 069ac184)
1#!/usr/bin/perl -w
2
3#
4#
5# This script compares the file iso639 (from head/share/misc) with the file
6# ISO-639-2_8859-1.txt (from
7# http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt) to see if there
8# any differences.
9#
10# Created by Edwin Groothuis <edwin@FreeBSD.org> for the FreeBSD project.
11#
12
13use strict;
14use Data::Dumper;
15
16my %old = ();
17{
18	open(FIN, "iso639") or die "Cannot open iso639 (should be in head/share/misc)";
19	my @lines = <FIN>;
20	close(FIN);
21	chomp(@lines);
22
23	foreach my $l (@lines) {
24		next if ($l =~ /^#/);
25		next if ($l eq "");
26
27		die "Bad line: $l\n"
28			if ($l !~ /^([a-z\-]*)[ \t]+([a-z\-]+)[ \t]+([a-z\-]+)[ \t]+(.*)/);
29		my $a2 = $1;
30		my $bib = $2;
31		my $term = $3;
32		my $name = $4;
33
34		$old{$bib}{a2} = $a2;
35		$old{$bib}{bib} = $bib;
36		$old{$bib}{term} = $term;
37		$old{$bib}{name} = $name;
38	}
39}
40
41my %new = ();
42{
43	open(FIN, "ISO-639-2_utf-8.txt") or die "Cannot open ISO-639-2_utf-8.txt, which can be retrieved from http://www.loc.gov/standards/iso639-2/ISO-639-2_utf-8.txt";
44	my @lines = <FIN>;
45	close(FIN);
46	chomp(@lines);
47
48	foreach my $l (@lines) {
49		my @a = split(/\|/, $l);
50		my $a2 = $a[2];
51		my $bib = $a[0];
52		my $term = $a[1];
53		my $name = $a[3];
54
55		$term = $bib if ($term eq "");
56
57		$new{$bib}{a2} = $a2;
58		$new{$bib}{bib} = $bib;
59		$new{$bib}{term} = $term;
60		$new{$bib}{name} = $name;
61	}
62}
63
64{
65	my $c = 0;
66	foreach my $bib (sort(keys(%old))) {
67		next if (defined $new{$bib});
68		print "In old but not new: $old{$bib}{a2}\t$old{$bib}{bib}\t$old{$bib}{term}\t$old{$bib}{name}\n";
69		$c++;
70	}
71	print "Found $c issues\n";
72}
73
74{
75	my $c = 0;
76	foreach my $bib (sort(keys(%new))) {
77		next if (defined $old{$bib});
78		print "In new but not old: $new{$bib}{a2}\t$new{$bib}{bib}\t$new{$bib}{term}\t$new{$bib}{name}\n";
79		$c++;
80	}
81	print "Found $c issues\n";
82}
83
84{
85	my $c = 0;
86	foreach my $bib (sort(keys(%old))) {
87		next if (!defined $new{$bib});
88		next if ($old{$bib}{a2} eq $new{$bib}{a2} &&
89			 $old{$bib}{bib} eq $new{$bib}{bib} &&
90			 $old{$bib}{term} eq $new{$bib}{term} &&
91			 $old{$bib}{name} eq $new{$bib}{name});
92		print "In old: $old{$bib}{a2}\t$old{$bib}{bib}\t$old{$bib}{term}\t$old{$bib}{name}\n";
93		print "In new: $new{$bib}{a2}\t$new{$bib}{bib}\t$new{$bib}{term}\t$new{$bib}{name}\n";
94		$c++;
95	}
96	print "Found $c issues\n";
97}
98