#! /usr/bin/perl # # $Id$ use strict; use warnings; 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