countries: only set short name if different
[sheet.git] / tools / mkcountries-geonames
index fe1acb729e4215bea12d7a0d2ddf464912d421ea..32883ec9511694ad739e7180c2b3a27843a1df01 100755 (executable)
@@ -38,31 +38,32 @@ my %cc;  # map of country code to info array
        yv => ["(Venezuela)", "c-sa Xr", undef, 've'],
 
        # WIPO, agreed not to use
-       ap => ["African Regional Industrial Property Organization", "c-af Xr", "ARIPO"],
-       bx => ["Benelux Office for Intellectual Property", "c-eu Xr", "BOIP"],
-       ef => ["European Community Patent Convention", "c-eu Xr", "CPC"],
-       em => ["European Trademark Office", "c-eu Xr", "OHIM"],
-       ep => ["European Patent Organization", "c-eu Xr", "EPOrg"],
-       ev => ["Eurasian Patent Organization", "c-as Xr", "EAPO"],
-       gc => ["Gulf Patent Office", "c-as Xr", "GCCPO"],
-       ib => ["International Bureau of WIPO", "Xr", "IB WIPO"],
-       oa => ["African Intellectual Property Organization", "c-af Xr", "OAPI"],
-       wo => ["World Intellectual Property Organization", "Xr", "WIPO"],
+       ap => ["African Regional Industrial Property Organization", "Xi", "ARIPO"], # c-af
+       bx => ["Benelux Office for Intellectual Property", "Xi", "BOIP"], # c-eu
+       ef => ["European Community Patent Convention", "Xi", "CPC"], # c-eu
+       em => ["European Trademark Office", "Xi", "OHIM"], # c-eu
+       ep => ["European Patent Organization", "Xi", "EPOrg"], # c-eu
+       ev => ["Eurasian Patent Organization", "Xi", "EAPO"], # c-as
+       gc => ["Gulf Patent Office", "Xi", "GCCPO"], # c-as
+       ib => ["International Bureau of WIPO", "Xi", "IB WIPO"],
+       oa => ["African Intellectual Property Organization", "Xi", "OAPI"], # c-af
+       wo => ["World Intellectual Property Organization", "Xi", "WIPO"],
 );
 
 while (<>) {
        /^#/ and next;  # skip comments
-       my ($iso, $name, $cont) = (split /\t/)[0, 4, 8];
-       $cont =~ s/\AAN\z/aa/;  # different antarctica abbreviation
-       my $class = "c-\L$cont";
-       $cc{ lc $iso } = [ $name, $class ];
+       my ($iso, $name, $cont, $tld) = (split /\t/)[0, 4, 8, 9];
+       my @info = ($name, "c-\L$cont");
+       $info[3] = $tld if $tld =~ s/\A\.// and $tld ne lc $iso;
+       $cc{ lc $iso } = \@info;
 }
 
 $cc{io}->[2] = "Chagos Islands";
 $cc{um}->[2] = "U.S. isl.";
 
 for (values %cc) {
-       for ($_->[2] //= $_->[0]) {
+       my $abbr = do {
+               local $_ = $_->[2] // $_->[0];
                s/,.*//;
                s/(?<=.)\(.*\)\s*//;
                s/ republic\b//gi;
@@ -77,7 +78,9 @@ for (values %cc) {
                s/New /n./g;
                s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
                s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
-       }
+               $_;
+       };
+       $_->[2] = $abbr if $abbr ne $_->[0];  # short name if different
 }
 
 say "# automatically generated by $0";