talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit fbfed23b5c4db507fb94df9f910bb1e2f846e2b1
parent 967a512bbcf98c5206bd8992f00a0de509174c0b
Author: Ricardo Mones <ricardo@mones.org>
Date:   Thu, 12 Nov 2015 17:31:20 +0100

Script to print IANA's TLD list as C array

Diffstat:
Atools/claws.get.tlds.pl | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+), 0 deletions(-)

diff --git a/tools/claws.get.tlds.pl b/tools/claws.get.tlds.pl @@ -0,0 +1,55 @@ +#!/usr/bin/perl -w +=pod +=head1 + +claws.get.tlds.pl - IANA TLDs online list to stdout as gchar* array. + +Copyright (c) 2015 Ricardo Mones <ricardo@mones.org> + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at your +option) any later version. + +This program is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program. If not, see <http://www.gnu.org/licenses/>. + +=cut +use 5.012; +use utf8; +use LWP::Simple; +use constant { + URL => "https://data.iana.org/TLD/tlds-alpha-by-domain.txt" +}; + +print "/*\n * This is a generated file.\n * See tools/claws.get.tlds.pl\n */\n"; +print "#ifndef __TLDS_H__\n#define __TLDS_H__\n\n"; +print "static const gchar *toplvl_domains [] = {\n\t"; # open array + +my $payload = get URL; +my @lines = split /^/, $payload; +my ($i, $j) = (0, 0); + +foreach (@lines) { + ++$i; + chomp; + if (/^#(.*)$/) { # comments + my $c = $1; $c =~ s/^\s+|\s+$//g; + print "/* $c */\n\t"; + next; + } + next if (/^XN--.*$/); # IDNs not supported yet, see bug #1670 + my $tld = lc $_; # list comes in upper case + print "\"$tld\""; ++$j; + print "," unless $i >= scalar @lines; + print "" . ($j % 5 == 0 or $i >= scalar @lines)? "\n": " "; + print "\t" if ($j % 5 == 0 and $i < scalar @lines); +} + +print "};\n\n"; # close array +print "#endif\n";