countries: prefer most significant country of .rb
[sheet.git] / tools / mkcountries-geonames
index 91daae753722d030e40af9340c1d6221f59377c0..f5a1cf1b626d209e52aa575bd763b13087adb248 100755 (executable)
@@ -24,7 +24,7 @@ my %cc;  # map of country code to info array
        lf => ["Libya Fezzan", "c-af Xr", "Fezzan", 'ly'],
        pi => ["(Philippines)", "c-as Xr", undef, 'ph'],
        ra => ["(Argentina)", "c-sa Xr", undef, 'ar'],
-       rb => ["Bolivia/Botswana", "c-xx Xr"],
+       rb => ["(Botswana, Bolivia)", "c-sa Xr", "(Bots...)"],
        rc => ["(RoC)", "c-as Xr", undef, 'tw'],
        rh => ["(Haiti)", "c-na Xr",undef, 'ht'],
        ri => ["(Indonesia)", "c-as Xr", undef, 'id'],
@@ -62,7 +62,8 @@ $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";