1#!/usr/bin/perl -w 2 3# 4# $FreeBSD$ 5# 6# This script compares the file iso3166 (from head/share/misc) with the files 7# list-en1-semic-3.txt (from 8# http://www.iso.org/iso/list-en1-semic-3.txt) and iso3166-countrycodes.txt 9# (from ftp://ftp.ripe.net/) to see if there any differences. 10# 11# Created by Edwin Groothuis <edwin@FreeBSD.org> for the FreeBSD project. 12# 13 14use strict; 15use Data::Dumper; 16 17my %old = (); 18{ 19 open(FIN, "iso3166") or die "Cannot open iso3166 (should be in head/share/misc)"; 20 my @lines = <FIN>; 21 close(FIN); 22 chomp(@lines); 23 24 foreach my $l (@lines) { 25 next if ($l =~ /^#/); 26 next if ($l eq ""); 27 28 die "Bad line: $l\n" 29 if ($l !~ /^([A-Z\-]*)[ \t]+([A-Z\-]+)[ \t]+(\d+)[ \t]+(.*)/); 30 my $two = $1; 31 my $three = $2; 32 my $number = $3; 33 my $name = $4; 34 35 $old{$two}{two} = $two; 36 $old{$two}{three} = $three; 37 $old{$two}{number} = $number; 38 $old{$two}{name} = $name; 39 } 40} 41 42my %new1 = (); 43{ 44 open(FIN, "iso3166-countrycodes.txt") or die "Cannot open iso3166-countrycodes.txt, which can be retrieved from ftp://ftp.ripe.net/iso3166-countrycodes.txt"; 45 my @lines = <FIN>; 46 close(FIN); 47 chomp(@lines); 48 49 my $noticed = 0; 50 foreach my $l (@lines) { 51 if ($l =~ /\-\-\-\-\-\-\-/) { 52 $noticed = 1; 53 next; 54 } 55 next if (!$noticed); 56 next if ($l eq ""); 57 58 die "Invalid line: $l\n" 59 if ($l !~ /^(.+?)[\t ]+([A-Z]{2})[\t ]+([A-Z]{3})[\t ]+(\d+)[\t ]*$/); 60 my $two = $2; 61 my $three = $3; 62 my $number = $4; 63 my $name = $1; 64 65 $new1{$two}{two} = $two; 66 $new1{$two}{three} = $three; 67 $new1{$two}{number} = $number; 68 $new1{$two}{name} = $name; 69 } 70} 71 72my %new2 = (); 73{ 74 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"; 75 my @lines = <FIN>; 76 close(FIN); 77 chomp(@lines); 78 79 my $noticed = 0; 80 foreach my $l (@lines) { 81 $l =~ s/\x0d//g; 82 if (!$noticed) { # skip the first line 83 $noticed = 1; 84 next; 85 } 86 next if ($l eq ""); 87 88 my @a = split(/;/, $l); 89 die "Invalid line: $l\n" if ($#a != 1); 90 my $two = $a[1]; 91 my $name = $a[0]; 92 93 $new2{$two}{two} = $two; 94 $new2{$two}{name} = $name; 95 } 96} 97 98{ 99 my $c = 0; 100 foreach my $two (sort(keys(%old))) { 101 if (!defined $new1{$two}) { 102 print "In old but not new1: $old{$two}{two}\t$old{$two}{three}\t$old{$two}{number}\t$old{$two}{name}\n"; 103 $c++; 104 } 105 if (!defined $new2{$two}) { 106 print "In old but not new2: $old{$two}{two}\t$old{$two}{name}\n"; 107 $c++; 108 } 109 } 110 print "Found $c issues\n"; 111} 112 113{ 114 my $c = 0; 115 foreach my $two (sort(keys(%new1))) { 116 next if (defined $old{$two}); 117 print "In new1 but not old: $new1{$two}{two}\t$new1{$two}{three}\t$new1{$two}{number}\t$new1{$two}{name}\n"; 118 $c++; 119 } 120 print "Found $c issues\n"; 121} 122 123{ 124 my $c = 0; 125 foreach my $two (sort(keys(%new2))) { 126 next if (defined $old{$two}); 127 print "In new2 but not old: $new2{$two}{two}\t$new2{$two}{name}\n"; 128 $c++; 129 } 130 print "Found $c issues\n"; 131} 132 133{ 134 my $c = 0; 135 foreach my $two (sort(keys(%old))) { 136 if (defined $new1{$two}) { 137 if ($old{$two}{two} ne $new1{$two}{two} || 138 $old{$two}{three} ne $new1{$two}{three} || 139 $old{$two}{number} ne $new1{$two}{number} || 140 lc($old{$two}{name}) ne lc($new1{$two}{name})) { 141 print "In old : $old{$two}{two}\t$old{$two}{three}\t$old{$two}{number}\t$old{$two}{name}\n"; 142 print "In new1: $new1{$two}{two}\t$new1{$two}{three}\t$new1{$two}{number}\t$new1{$two}{name}\n"; 143 $c++; 144 } 145 } 146 } 147 print "Found $c issues\n"; 148} 149 150{ 151 my $c = 0; 152 foreach my $two (sort(keys(%old))) { 153 if (defined $new2{$two}) { 154 if ($old{$two}{two} ne $new2{$two}{two} || 155 lc($old{$two}{name}) ne lc($new2{$two}{name})) { 156 print "In old : $old{$two}{two}\t$old{$two}{name}\n"; 157 print "In new2: $new2{$two}{two}\t$new2{$two}{name}\n"; 158 $c++; 159 } 160 } 161 } 162 print "Found $c issues\n"; 163} 164 165