Reloading detection finally implementet (mtime-dependent)
authorshort <>
Mon, 1 Jul 2002 17:36:55 +0000 (17:36 +0000)
committershort <>
Mon, 1 Jul 2002 17:36:55 +0000 (17:36 +0000)
Fixed invalid /s option for line processing although it was probably harmless
Optimization: Regex is now qr-precompiled

redirector

index 1d7718b..f72d82d 100755 (executable)
@@ -11,23 +11,35 @@ 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 (<M4>) {
-       chomp;
-       next if !$_;
-       $patt.="|" if $patt;
-       $patt.=$_."(?{ '";
-       s/'/'."'".'/g;
-       $patt.="$_'; })";
-       }
-close M4;
-
 select STDOUT;
 $|=1;
-
-while (<>) {
-       s@^http://($patt).*\n$@http://localhost/cgi-bin/redirector-ad.cgi?$^R\n@os;
-       print;
-       }
+my @got;
+
+RELOAD: {
+       my $patt="";
+       open(M4,"-|","m4 --prefix-builtins --synclines main") or die "m4 run: $!";
+       my %files;
+       while (<M4>) {
+               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