X-Git-Url: http://git.jankratochvil.net/?p=redirector-ad.git;a=blobdiff_plain;f=redirector;h=f72d82d443be62e3fc38a3a9ef941d2fc2a0dc8f;hp=74d3b58bb92dde3229a3a8aa0f5f5412ae161206;hb=70c905952a436bff2d87e26088407dec8b0c2d81;hpb=bd162fe51595efd781f2dfd4d35191c40a61a478 diff --git a/redirector b/redirector index 74d3b58..f72d82d 100755 --- a/redirector +++ b/redirector @@ -5,25 +5,41 @@ use strict; use warnings; +use re 'eval'; + use constant DIR_AD => "/usr/local/squid/etc/ad"; chdir DIR_AD or die "chdir ".DIR_AD.": $!"; - -my($patt)=""; -open(M4,"-|","m4 -P main") or die "m4 run: $!"; -while () { - chomp; - next if !$_; - $patt.="|" if $patt; - $patt.=$_; - } -close M4; - 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 (<>) { - s@^http://($patt).*\n$@http://localhost/cgi-bin/redirector-ad.cgi?$1\n@os; - print; - } + 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