From 6ffe07f8f6453d201005fae0a28299cb7ddec15b Mon Sep 17 00:00:00 2001 From: hackademix Date: Wed, 5 Sep 2018 13:33:38 +0200 Subject: Reduced noise from tld.js regular expressions generation. --- .gitignore | 1 + TLD/generate.pl | 7 +++---- TLD/generate.sh | 12 ++++++++---- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 27445ef..63af0ce 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ # build artifacts xpi *.xpi +*.bak # dev env options .eslintrc.json # auto-generated files diff --git a/TLD/generate.pl b/TLD/generate.pl index e37ffd5..8f6709a 100644 --- a/TLD/generate.pl +++ b/TLD/generate.pl @@ -16,7 +16,7 @@ sub generate { s/\s+utf.*//; s/[\r\n]//g; if(/^!/) { - s/^!//; + s/^!//; push(@ex, lc($_)); } elsif (!/^(\/\/|[ \n\r]|$)/) { s/\*\\\./[^\\.]+\\./; @@ -24,7 +24,7 @@ sub generate { } } close(DAT); - + #$o = Regexp::Optimizer->new; #$o = Regexp::List->new; $o = Regexp::Assemble->new; @@ -38,14 +38,13 @@ sub generate { s/\(\?-xism:(.*)\)/$1/; $ex = $_; @ex = NULL; - + open(SRC, $src) || die("Cannot open $src"); open(DST, ">$dst") || die("Cannot open $dst"); while() { s/(_tldRx:\s*\/\(.*?\)).*?(?=\$\/)/$1$rx/s; s/(_tldEx:\s*\/\(.*?\)).*?(?=\$\/)/$1$ex/s; print DST; - print; } close(SRC); close(DST); diff --git a/TLD/generate.sh b/TLD/generate.sh index b05af33..9ccace7 100644 --- a/TLD/generate.sh +++ b/TLD/generate.sh @@ -1,16 +1,19 @@ #!/bin/bash BASE=$(dirname "$0") +TEMPLATE=tld_template.js if [ -f "$1" ]; then - cp "$1" "$BASE/tld_template.js" + cp "$1" "$BASE/$TEMPLATE" fi -pushd "$BASE" +pushd "$BASE" >/dev/null fname=public_suffix_list.dat nflag="" if [ -f "$fname" ]; then nflag="-z $fname" + cp "$fname" "$fname.bak" fi +echo 'Updating TLDs...' URL=https://publicsuffix.org/list/$fname -curl -O $nflag "$URL" +curl -sO $nflag "$URL" if ! grep 'com' "$fname" >/dev/null; then echo >&2 "$fname empty or corrupt!" @@ -18,4 +21,5 @@ if ! grep 'com' "$fname" >/dev/null; then fi ./generate.pl -popd +[ -f "$fname.bak" ] && diff "$fname" "$fname.bak" && echo 'No new data from pubblic suffix list.' +popd >/dev/null -- cgit v1.2.3