xref: /freebsd/tools/tools/iso/check-iso3166.pl (revision d0b2dbfa)
18c8e796bSEdwin Groothuis#!/usr/bin/perl -w
28c8e796bSEdwin Groothuis
38c8e796bSEdwin Groothuis#
48c8e796bSEdwin Groothuis#
58c8e796bSEdwin Groothuis# This script compares the file iso3166 (from head/share/misc) with the files
6c5917de7SUlrich Spörlein# list-en1-semic-3.txt (from
7c5917de7SUlrich Spörlein# http://www.iso.org/iso/list-en1-semic-3.txt) and iso3166-countrycodes.txt
88c8e796bSEdwin Groothuis# (from ftp://ftp.ripe.net/) to see if there any differences.
98c8e796bSEdwin Groothuis#
108c8e796bSEdwin Groothuis# Created by Edwin Groothuis <edwin@FreeBSD.org> for the FreeBSD project.
118c8e796bSEdwin Groothuis#
128c8e796bSEdwin Groothuis
138c8e796bSEdwin Groothuisuse strict;
148c8e796bSEdwin Groothuisuse Data::Dumper;
158c8e796bSEdwin Groothuis
168c8e796bSEdwin Groothuismy %old = ();
178c8e796bSEdwin Groothuis{
188c8e796bSEdwin Groothuis	open(FIN, "iso3166") or die "Cannot open iso3166 (should be in head/share/misc)";
198c8e796bSEdwin Groothuis	my @lines = <FIN>;
208c8e796bSEdwin Groothuis	close(FIN);
218c8e796bSEdwin Groothuis	chomp(@lines);
228c8e796bSEdwin Groothuis
238c8e796bSEdwin Groothuis	foreach my $l (@lines) {
248c8e796bSEdwin Groothuis		next if ($l =~ /^#/);
258c8e796bSEdwin Groothuis		next if ($l eq "");
268c8e796bSEdwin Groothuis
278c8e796bSEdwin Groothuis		die "Bad line: $l\n"
288c8e796bSEdwin Groothuis			if ($l !~ /^([A-Z\-]*)[ \t]+([A-Z\-]+)[ \t]+(\d+)[ \t]+(.*)/);
298c8e796bSEdwin Groothuis		my $two = $1;
308c8e796bSEdwin Groothuis		my $three = $2;
318c8e796bSEdwin Groothuis		my $number = $3;
328c8e796bSEdwin Groothuis		my $name = $4;
338c8e796bSEdwin Groothuis
348c8e796bSEdwin Groothuis		$old{$two}{two} = $two;
358c8e796bSEdwin Groothuis		$old{$two}{three} = $three;
368c8e796bSEdwin Groothuis		$old{$two}{number} = $number;
378c8e796bSEdwin Groothuis		$old{$two}{name} = $name;
388c8e796bSEdwin Groothuis	}
398c8e796bSEdwin Groothuis}
408c8e796bSEdwin Groothuis
418c8e796bSEdwin Groothuismy %new1 = ();
428c8e796bSEdwin Groothuis{
43c5917de7SUlrich Spörlein	open(FIN, "iso3166-countrycodes.txt") or die "Cannot open iso3166-countrycodes.txt, which can be retrieved from ftp://ftp.ripe.net/iso3166-countrycodes.txt";
448c8e796bSEdwin Groothuis	my @lines = <FIN>;
458c8e796bSEdwin Groothuis	close(FIN);
468c8e796bSEdwin Groothuis	chomp(@lines);
478c8e796bSEdwin Groothuis
488c8e796bSEdwin Groothuis	my $noticed = 0;
498c8e796bSEdwin Groothuis	foreach my $l (@lines) {
508c8e796bSEdwin Groothuis		if ($l =~ /\-\-\-\-\-\-\-/) {
518c8e796bSEdwin Groothuis			$noticed = 1;
528c8e796bSEdwin Groothuis			next;
538c8e796bSEdwin Groothuis		}
548c8e796bSEdwin Groothuis		next if (!$noticed);
558c8e796bSEdwin Groothuis		next if ($l eq "");
568c8e796bSEdwin Groothuis
578c8e796bSEdwin Groothuis		die "Invalid line: $l\n"
58c5917de7SUlrich Spörlein			if ($l !~ /^(.+?)[\t ]+([A-Z]{2})[\t ]+([A-Z]{3})[\t ]+(\d+)[\t ]*$/);
598c8e796bSEdwin Groothuis		my $two = $2;
608c8e796bSEdwin Groothuis		my $three = $3;
618c8e796bSEdwin Groothuis		my $number = $4;
628c8e796bSEdwin Groothuis		my $name = $1;
638c8e796bSEdwin Groothuis
648c8e796bSEdwin Groothuis		$new1{$two}{two} = $two;
658c8e796bSEdwin Groothuis		$new1{$two}{three} = $three;
668c8e796bSEdwin Groothuis		$new1{$two}{number} = $number;
678c8e796bSEdwin Groothuis		$new1{$two}{name} = $name;
688c8e796bSEdwin Groothuis	}
698c8e796bSEdwin Groothuis}
708c8e796bSEdwin Groothuis
718c8e796bSEdwin Groothuismy %new2 = ();
728c8e796bSEdwin Groothuis{
73c5917de7SUlrich Spörlein	open(FIN, "list-en1-semic-3.txt") or die "Cannot open list-en1-semic-3.txt, which can be retrieved from http://www.iso.org/iso/list-en1-semic-3.txt";
748c8e796bSEdwin Groothuis	my @lines = <FIN>;
758c8e796bSEdwin Groothuis	close(FIN);
768c8e796bSEdwin Groothuis	chomp(@lines);
778c8e796bSEdwin Groothuis
788c8e796bSEdwin Groothuis	my $noticed = 0;
798c8e796bSEdwin Groothuis	foreach my $l (@lines) {
808c8e796bSEdwin Groothuis		$l =~ s/\x0d//g;
818c8e796bSEdwin Groothuis		if (!$noticed) {	# skip the first line
828c8e796bSEdwin Groothuis			$noticed = 1;
838c8e796bSEdwin Groothuis			next;
848c8e796bSEdwin Groothuis		}
858c8e796bSEdwin Groothuis		next if ($l eq "");
868c8e796bSEdwin Groothuis
878c8e796bSEdwin Groothuis		my @a = split(/;/, $l);
888c8e796bSEdwin Groothuis		die "Invalid line: $l\n" if ($#a != 1);
898c8e796bSEdwin Groothuis		my $two = $a[1];
908c8e796bSEdwin Groothuis		my $name = $a[0];
918c8e796bSEdwin Groothuis
928c8e796bSEdwin Groothuis		$new2{$two}{two} = $two;
938c8e796bSEdwin Groothuis		$new2{$two}{name} = $name;
948c8e796bSEdwin Groothuis	}
958c8e796bSEdwin Groothuis}
968c8e796bSEdwin Groothuis
978c8e796bSEdwin Groothuis{
988c8e796bSEdwin Groothuis	my $c = 0;
998c8e796bSEdwin Groothuis	foreach my $two (sort(keys(%old))) {
1008c8e796bSEdwin Groothuis		if (!defined $new1{$two}) {
1018c8e796bSEdwin Groothuis			print "In old but not new1: $old{$two}{two}\t$old{$two}{three}\t$old{$two}{number}\t$old{$two}{name}\n";
1028c8e796bSEdwin Groothuis			$c++;
1038c8e796bSEdwin Groothuis		}
1048c8e796bSEdwin Groothuis		if (!defined $new2{$two}) {
1058c8e796bSEdwin Groothuis			print "In old but not new2: $old{$two}{two}\t$old{$two}{name}\n";
1068c8e796bSEdwin Groothuis			$c++;
1078c8e796bSEdwin Groothuis		}
1088c8e796bSEdwin Groothuis	}
1098c8e796bSEdwin Groothuis	print "Found $c issues\n";
1108c8e796bSEdwin Groothuis}
1118c8e796bSEdwin Groothuis
1128c8e796bSEdwin Groothuis{
1138c8e796bSEdwin Groothuis	my $c = 0;
1148c8e796bSEdwin Groothuis	foreach my $two (sort(keys(%new1))) {
1158c8e796bSEdwin Groothuis		next if (defined $old{$two});
1168c8e796bSEdwin Groothuis		print "In new1 but not old: $new1{$two}{two}\t$new1{$two}{three}\t$new1{$two}{number}\t$new1{$two}{name}\n";
1178c8e796bSEdwin Groothuis		$c++;
1188c8e796bSEdwin Groothuis	}
1198c8e796bSEdwin Groothuis	print "Found $c issues\n";
1208c8e796bSEdwin Groothuis}
1218c8e796bSEdwin Groothuis
1228c8e796bSEdwin Groothuis{
1238c8e796bSEdwin Groothuis	my $c = 0;
1248c8e796bSEdwin Groothuis	foreach my $two (sort(keys(%new2))) {
1258c8e796bSEdwin Groothuis		next if (defined $old{$two});
1268c8e796bSEdwin Groothuis		print "In new2 but not old: $new2{$two}{two}\t$new2{$two}{name}\n";
1278c8e796bSEdwin Groothuis		$c++;
1288c8e796bSEdwin Groothuis	}
1298c8e796bSEdwin Groothuis	print "Found $c issues\n";
1308c8e796bSEdwin Groothuis}
1318c8e796bSEdwin Groothuis
1328c8e796bSEdwin Groothuis{
1338c8e796bSEdwin Groothuis	my $c = 0;
1348c8e796bSEdwin Groothuis	foreach my $two (sort(keys(%old))) {
1358c8e796bSEdwin Groothuis		if (defined $new1{$two}) {
1368c8e796bSEdwin Groothuis			if ($old{$two}{two} ne $new1{$two}{two} ||
1378c8e796bSEdwin Groothuis			    $old{$two}{three} ne $new1{$two}{three} ||
1388c8e796bSEdwin Groothuis			    $old{$two}{number} ne $new1{$two}{number} ||
1398c8e796bSEdwin Groothuis			    lc($old{$two}{name}) ne lc($new1{$two}{name})) {
1408c8e796bSEdwin Groothuis				print "In old : $old{$two}{two}\t$old{$two}{three}\t$old{$two}{number}\t$old{$two}{name}\n";
1418c8e796bSEdwin Groothuis				print "In new1: $new1{$two}{two}\t$new1{$two}{three}\t$new1{$two}{number}\t$new1{$two}{name}\n";
1428c8e796bSEdwin Groothuis				$c++;
1438c8e796bSEdwin Groothuis			}
1448c8e796bSEdwin Groothuis		}
1458c8e796bSEdwin Groothuis	}
1468c8e796bSEdwin Groothuis	print "Found $c issues\n";
1478c8e796bSEdwin Groothuis}
1488c8e796bSEdwin Groothuis
1498c8e796bSEdwin Groothuis{
1508c8e796bSEdwin Groothuis	my $c = 0;
1518c8e796bSEdwin Groothuis	foreach my $two (sort(keys(%old))) {
1528c8e796bSEdwin Groothuis		if (defined $new2{$two}) {
1538c8e796bSEdwin Groothuis			if ($old{$two}{two} ne $new2{$two}{two} ||
1548c8e796bSEdwin Groothuis			    lc($old{$two}{name}) ne lc($new2{$two}{name})) {
1558c8e796bSEdwin Groothuis				print "In old : $old{$two}{two}\t$old{$two}{name}\n";
1568c8e796bSEdwin Groothuis				print "In new2: $new2{$two}{two}\t$new2{$two}{name}\n";
1578c8e796bSEdwin Groothuis				$c++;
1588c8e796bSEdwin Groothuis			}
1598c8e796bSEdwin Groothuis		}
1608c8e796bSEdwin Groothuis	}
1618c8e796bSEdwin Groothuis	print "Found $c issues\n";
1628c8e796bSEdwin Groothuis}
1638c8e796bSEdwin Groothuis
164