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