charset: update bmp allocation to unicode v9.0 roadmap
[sheet.git] / tools / mkcountries-geonames
1 #!/usr/bin/env perl
2 use 5.012;
3 use warnings;
4
5 my %cc;  # map of country code to info array
6 %cc = (
7         # transitional reservations
8         an => ["transitionally reserved: Netherlands Antilles", "c-na Xr", "Netherlands Antilles", 'bq cw sx'], # 2060
9         bu => ["transitionally reserved: Burma", "c-as Xr", "Burma", 'mm'], # 2039
10         cs => ["transitionally reserved: Serbia and Montenegro", "c-eu Xr", "Serbia and Montenegro", 'rs me'], # 2056
11         nt => ["transitionally reserved: Neutral Zone", "c-as Xr", "N. Zone", 'iq sa'], # 2043
12         tp => ["transitionally reserved: East Timor", "c-oc Xr", "(East Timor)", 'tl'], # 2052
13         yu => ["transitionally reserved: Yugoslavia", "c-eu Xr", "Yugoslavia", 'cs ba hr mk si'], # 2053
14         zr => ["transitionally reserved: Zaire", "c-af Xr", "Zaire", 'cd'], # 2047
15
16         # exceptional reservations
17         ac => ["exceptionally reserved: Ascension Island", "c-oc Xr", "Ascension Island", 'sh'],
18         cp => ["exceptionally reserved: Clipperton Island", "c-na Xr", "Clipperton Island"],
19         dg => ["exceptionally reserved: Diego Garcia", "c-as Xr", "Diego Garcia", 'io'],
20         ea => ["exceptionally reserved: Ceuta and Melilla", "c-af Xr", "Ceuta and Melilla"],
21         eu => ["exceptionally reserved: European Union", "c-eu Xr", "European Union"],
22         ez => ["exceptionally reserved: European OTC derivatives", "c-eu Xr", "Eurozone"],
23         fx => ["exceptionally reserved: Metropolitan France", "c-eu Xr", "Metropolitan France", 'fr'],
24         ic => ["exceptionally reserved: Canary Islands", "c-af Xr", "Canary Islands"],
25         su => ["exceptionally reserved: former USSR", "c-eu Xr", "USSR"],
26         ta => ["exceptionally reserved: Tristan da Cunha", "c-oc Xr", "Tristan da Cunha", 'sh'],
27         uk => ["exceptionally reserved: United Kingdom", "c-eu Xr", "(United Kingdom)", 'gb'],
28         un => ["exceptionally reserved: United Nations", "Xi Xr", "United Nations"],
29
30         # indeterminate reservations
31         dy => ["indeterminately reserved: Benin", "c-af Xr", "(Benin)", 'bj'],
32         ew => ["indeterminately reserved: Estonia", "c-eu Xr", "(Estonia)", 'ee'],
33         fl => ["indeterminately reserved: Liechtenstein", "c-eu Xr", "(Liechtenstein)", 'li'],
34         ja => ["indeterminately reserved: Jamaica", "c-na Xr", "(Jamaica)", 'jm'],
35         lf => ["indeterminately reserved: Libya Fezzan", "c-af Xr", "Fezzan", 'ly'],
36         pi => ["indeterminately reserved: Philippines", "c-as Xr", "(Philippines)", 'ph'],
37         ra => ["indeterminately reserved: Argentina", "c-sa Xr", "(Argentina)", 'ar'],
38         rb => ["indeterminately reserved: Botswana, Bolivia", "c-sa Xr", "(Bots...)", 'bw bo'],
39         rc => ["indeterminately reserved: Republic of China", "c-as Xr", "(RoC)", 'tw'],
40         rh => ["indeterminately reserved: Haiti", "c-na Xr", "(Haiti)", 'ht'],
41         ri => ["indeterminately reserved: Indonesia", "c-as Xr", "(Indonesia)", 'id'],
42         rl => ["indeterminately reserved: Lebanon", "c-as Xr", "(Lebanon)", 'lb'],
43         rm => ["indeterminately reserved: Madagascar", "c-af Xr", "(Madagascar)", 'mg'],
44         rn => ["indeterminately reserved: Niger", "c-af Xr", "(Niger)", 'ne'],
45         rp => ["indeterminately reserved: Philippines", "c-as Xr", "(Philippines)", 'ph'],
46         sf => ["indeterminately reserved: Finland", "c-eu Xr", "(Finland)", 'fi'],
47         wg => ["indeterminately reserved: Grenada", "c-na Xr", "(Grenada)", 'gd'],
48         wl => ["indeterminately reserved: Saint Lucia", "c-na Xr", "(Saint Luc.)", 'lc'],
49         wv => ["indeterminately reserved: Saint Vincent", "c-na Xr", "(Saint Vin.)", 'vc'],
50         yv => ["indeterminately reserved: Venezuela", "c-sa Xr", "(Venezuela)", 've'],
51
52         # WIPO, agreed not to use
53         ap => ["not used: African Regional Industrial Property Organization", "Xi", "ARIPO"], # c-af
54         bx => ["not used: Benelux Office for Intellectual Property", "Xi", "BOIP"], # c-eu
55         ef => ["not used: European Community Patent Convention", "Xi", "CPC"], # c-eu
56         em => ["not used: European Trademark Office", "Xi", "OHIM"], # c-eu
57         ep => ["not used: European Patent Organization", "Xi", "EPOrg"], # c-eu
58         ev => ["not used: Eurasian Patent Organization", "Xi", "EAPO"], # c-as
59         gc => ["not used: Gulf Patent Office", "Xi", "GCCPO"], # c-as
60         ib => ["not used: International Bureau of WIPO", "Xi", "IB"],
61         oa => ["not used: African Intellectual Property Organization", "Xi", "OAPI"], # c-af
62         wo => ["not used: World Intellectual Property Organization", "Xi", "WIPO"],
63
64         # common user-assigned
65         xz => ["UN/LOCODE semantics: international waters", "Co Xi", "international"],
66         qo => ["Unicode semantics: Outlying Oceania", "c-oc Co Xi", "Oceania"],
67         qu => ["Unicode semantics: European Union deprecated reserve", "c-eu Co Xi", "EU", 'eu'],
68         zz => ["Unicode semantics: unknown or invalid territory", "Co Xi","unknown"],
69 );
70
71 while (<>) {
72         /^#/ and next;  # skip comments
73         my ($iso, $name, $cont, $tld) = (split /\t/)[0, 4, 8, 9];
74         my @info = ($name, "c-\L$cont");
75         $info[3] = $tld if $tld =~ s/\A\.// and $tld ne lc $iso;
76         $cc{ lc $iso } //= \@info;
77 }
78
79 $cc{io}->[2] = "Chagos Islands";
80 $cc{um}->[2] = "U.S. isl.";
81
82 for (values %cc) {
83         my $abbr = do {
84                 local $_ = $_->[2] // $_->[0];
85                 s/,.*//;
86                 s/(?<=.)\(.*\)\s*//;
87                 s/ republic\b//gi;
88                 s/ islands?\b//gi;
89                 s/\bthe //g;
90                 s/ and / & /g and s/(?<=.)[a-z ]+//g;
91                 s/ of / /g;
92                 s/\bsa?int /st /gi;
93                 s/United /Un. /gi;
94                 s/South(?:ern)? /S-/g;
95                 s/North(?:ern)? /N-/g;
96                 s/New /n./g;
97                 s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
98                 s/(\S{4}[b-df-hj-np-tv-xz])((?<!Austr)(?!land)\w{2,})/$1./g;  # abbreviate (at consonant)
99                 $_;
100         };
101         $_->[2] = $abbr if $abbr ne $_->[0];  # short name if different
102 }
103
104 say "# automatically generated by $0";
105 use Data::Dump 'dd';
106 $Data::Dump::INDENT = '';
107 dd \%cc;
108
109 __END__
110
111 =head1 NAME
112
113 mkcountries-geonames - Create Perl include of country info from GeoNames data
114
115 =head1 SYNOPSIS
116
117         curl http://download.geonames.org/export/dump/countryInfo.txt |
118         tools/mkcountryinfo > countries.inc.pl
119