File: gen_tld.pl

package info (click to toggle)
htmlcxx 0.87-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,412 kB
  • sloc: sh: 4,380; cpp: 4,355; yacc: 526; ansic: 205; lex: 159; makefile: 47; perl: 27
file content (33 lines) | stat: -rwxr-xr-x 873 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl -w

print "/** Do not modify. This file is automatically generated\n";
print "  * using gen_tld.pl and tld.list\n";
print "  */\n\n";
		
my @tld;
while(<STDIN>) {
	chomp;
	if(/^([\w\.]+)\s+/) {
		push @tld, uc $1;
	}
}
@tld = sort { length($a) <=> length($b) || $a cmp $b } @tld;
@tld = reverse @tld;

my $i;
print "static const char *tld[] = {\n";
for($i = 0; $i < scalar (@tld) - 1; ++$i) { print "\t\".$tld[$i]\",\n"; }
print "\t\"." . $tld[scalar(@tld) - 1] . "\"\n";
print "};\n";
print "static uint tldOffset(const char *domain) {\n";
print "	const char *end = domain + strlen(domain);\n";
print "	for(unsigned int i = 0; i < " . scalar @tld . "; ++i) {\n";
print " 	unsigned int len = strlen(tld[i]);\n";
print "		if(strcasecmp(end - len, tld[i]) == 0) {\n";
print "			return len;\n";
print "		}\n";
print "	}\n";
print " return 0;";
print "}\n";