X-Git-Url: https://git.jankratochvil.net/?p=redirector-ad.git;a=blobdiff_plain;f=redirector;h=f72d82d443be62e3fc38a3a9ef941d2fc2a0dc8f;hp=fd8920cdf4ece863ffd508eba3aecae342d6ae85;hb=ef4fbe01d463c32814c98a0cc42842a2068c5a80;hpb=082ee6d79964c95554b8ac0f0d145f451d0c5ca3 diff --git a/redirector b/redirector index fd8920c..f72d82d 100755 --- a/redirector +++ b/redirector @@ -1,9 +1,45 @@ -#! /bin/sh +#! /usr/bin/perl # # $Id$ -DIR_AD=/usr/local/squid/etc/ad +use strict; +use warnings; -exec /usr/bin/perl -e '$|=1; while (<>) { -'"` (cd "$DIR_AD";m4 -P main)|awk '/./{print "s@^http://"$0".*$@http://localhost/cgi-bin/redirector-ad.cgi?"$0"@;"}' `"' -print; }' +use re 'eval'; + +use constant DIR_AD => "/usr/local/squid/etc/ad"; + + +chdir DIR_AD or die "chdir ".DIR_AD.": $!"; +select STDOUT; +$|=1; +my @got; + +RELOAD: { + my $patt=""; + open(M4,"-|","m4 --prefix-builtins --synclines main") or die "m4 run: $!"; + my %files; + while () { + chomp; + next if !$_; + do { $files{$1}=undef; next; } if /^#\s*line\s+\d+\s+"(.*)"$/; + $patt.="|" if $patt; + $patt.=$_."(?{ '"; + s/'/'."'".'/g; + $patt.="$_'; })"; + } + close M4; + $patt=qr @^http://($patt).*\n$@; + + while ($_=shift @got || <>) { + while (my($file,$old)=each %files) { + my $new=(stat $file)[9]; + $files{$file}=$new; + next if !defined $old || $old==$new; + push @got,$_; + redo RELOAD; + } + s@$patt@http://localhost/cgi-bin/redirector-ad.cgi?$^R\n@; + print; + } + } # RELOAD