cc: names by default
[sheet.git] / cc.plp
1 <:
2 use utf8;
3 use strict;
4 use warnings;
5 use open IO => ':utf8';
6
7 our $VERSION = 'v1.0';
8
9 $header{content_type} = 'text/html; charset=utf-8';
10
11 :><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
12  "http://www.w3.org/TR/html4/loose.dtd">
13 <html>
14
15 <head>
16 <meta http-equiv="content-type" content="<:= $header{content_type} :>">
17 <title>country code cheat sheet</title>
18 <link rel="stylesheet" type="text/css" media="all" href="/base.css">
19 </head>
20
21 <body>
22 <h1>Country codes</h1>
23
24 <:
25 my $cc = do 'cc.inc.pl';
26
27 sub quote {
28         local $_ = shift;
29         s/"/&quot;/g;
30         s/</&lt;/g;
31         s/>/&gt;/g;
32         return $_;
33 }
34
35 {
36         printf '<table class="mcmap">';
37         print '<col>';
38         for my $section (qw{thead}) {
39                 print "<$section><tr><th>↱";
40                 print '<th>', $_ for 'a' .. 'z';
41                 print "\n";
42         }
43         print '<tbody>';
44         for my $row ('a' .. 'z') {
45                 print '<tr><th>', $row;
46                 for my $col ('a' .. 'z') {
47                         my $code = $row . $col;
48                         my $country = $cc->{$code} or do {
49                                 print $code =~ /^x|^q[m-z]|^aa|^zz/ ? '<td class="X Co">' : '<td>';
50                                 next;
51                         };
52                         my ($name, $class, $short, $ref) = @$country;
53                         $ref ||= $code;
54                         local $_ = $ref;
55                         if (exists $get{show}) {
56                                 my $img = "flag/$ref.png";
57                                 $_ = sprintf '<img src="/%s" alt="%s">', $img, $ref if -e $img;
58                         }
59                         else {
60                                 $_ = $short || $name;
61                                 s/,.*//;
62                                 s/(?<=.)\(.*\)\s*//;
63                                 s/ republic\b//gi;
64                                 s/ islands?\b//gi;
65                                 s/\bthe //g;
66                                 s/ and / & /g;
67                                 s/\bsaint /st /gi;
68                                 s/South /S-/g;
69                                 s/North /N-/g;
70                                 s/New /n./g;
71                                 s/(\S)(\S+)-/$1-/g;  # strip most chars preceding dash
72                                 s/(\S{4}[b-df-hj-np-tv-xz])(\S{2,})/$1./g;  # abbreviate (at consonant)
73                                 $_ = quote($_);
74                         }
75                         $name =~ s/([^,]*), (.*)/$2 $1/;
76                         printf "\n".'<td class="%s" title="%s">%s',
77                                 $_ ? 'X '.$class : '', quote("$code: $name"), $_;
78                 }
79                 print "\n";
80         }
81         print "</table>\n";
82 }
83
84 :>
85 <hr>
86
87 <div class="legend">
88         <table class="glyphs"><tr>
89         <td class="X c-af">africa
90         <td class="X c-eu">europe
91         <td class="X c-as">asia
92         <td class="X c-oc">oceania
93         <td class="X c-aa">antarctica
94         <td class="X c-sa">south america
95         <td class="X c-na">north america
96         <td class="X Xi">reserved
97         <td class="X Co">user-assigned
98         </table>
99 </div>
100
101 <p class="footer">
102         <a href="/" rel="home">sheet.shiar.nl</a>/charset
103         <a href="git://git.shiar.nl/sheet" rel="vcs-git" title="Git repository"><:= $VERSION :></a>
104         created by <a href="http://shiar.nl/" rel="author">Shiar</a> •
105         <a title="Licensed under the GNU Affero General Public License, version 3" rel="copyright"
106            href="http://www.fsf.org/licensing/licenses/agpl-3.0.html">AGPLv3</a>
107 </p>
108
109 </html>