2018-06-30 17:01:23 -06:00
|
|
|
#!/usr/bin/perl -w
|
2021-06-18 16:21:23 -06:00
|
|
|
|
2024-10-18 00:41:59 -06:00
|
|
|
# Copyright (C) 2005-2024 Giorgio Maone <https://maone.net>
|
2021-06-18 16:21:23 -06:00
|
|
|
#
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
# use strict;
|
2018-08-02 06:40:44 -06:00
|
|
|
use utf8;
|
2018-06-30 17:01:23 -06:00
|
|
|
use open ':utf8';
|
|
|
|
use Regexp::Assemble;
|
|
|
|
$dat="public_suffix_list.dat";
|
|
|
|
die(".dat file $dat not found!") unless -f "$dat";
|
|
|
|
|
|
|
|
sub generate {
|
|
|
|
my $src = "./tld_template.js";
|
|
|
|
my $dst = "./tld.js";
|
|
|
|
my (@rx, @ex, $rx, $ex);
|
|
|
|
open(DAT, $dat) || die("Cannot open $dat");
|
|
|
|
while(<DAT>) {
|
|
|
|
s/\./\\\./g;
|
|
|
|
s/\s+utf.*//;
|
2018-08-29 10:21:24 -06:00
|
|
|
s/[\r\n]//g;
|
2018-06-30 17:01:23 -06:00
|
|
|
if(/^!/) {
|
2018-09-05 05:33:38 -06:00
|
|
|
s/^!//;
|
2018-06-30 17:01:23 -06:00
|
|
|
push(@ex, lc($_));
|
|
|
|
} elsif (!/^(\/\/|[ \n\r]|$)/) {
|
|
|
|
s/\*\\\./[^\\.]+\\./;
|
|
|
|
push(@rx, lc($_));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
close(DAT);
|
2018-09-05 05:33:38 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
#$o = Regexp::Optimizer->new;
|
|
|
|
#$o = Regexp::List->new;
|
|
|
|
$o = Regexp::Assemble->new;
|
|
|
|
$_ = $o->add(@rx)->as_string();
|
|
|
|
s/\(\?-xism:(.*)\)/$1/;
|
|
|
|
$rx = $_;
|
|
|
|
@rx = NULL;
|
|
|
|
|
|
|
|
$o = Regexp::Assemble->new;
|
|
|
|
$_ = $o->add(@ex)->as_string();
|
|
|
|
s/\(\?-xism:(.*)\)/$1/;
|
|
|
|
$ex = $_;
|
|
|
|
@ex = NULL;
|
2018-09-05 05:33:38 -06:00
|
|
|
|
2018-06-30 17:01:23 -06:00
|
|
|
open(SRC, $src) || die("Cannot open $src");
|
|
|
|
open(DST, ">$dst") || die("Cannot open $dst");
|
|
|
|
while(<SRC>) {
|
2018-08-29 10:21:24 -06:00
|
|
|
s/(_tldRx:\s*\/\(.*?\)).*?(?=\$\/)/$1$rx/s;
|
|
|
|
s/(_tldEx:\s*\/\(.*?\)).*?(?=\$\/)/$1$ex/s;
|
2018-06-30 17:01:23 -06:00
|
|
|
print DST;
|
|
|
|
}
|
|
|
|
close(SRC);
|
|
|
|
close(DST);
|
|
|
|
}
|
|
|
|
generate();
|