Rewritten to Perl to cure the slowness
authorshort <>
Sun, 25 Nov 2001 22:00:59 +0000 (22:00 +0000)
committershort <>
Sun, 25 Nov 2001 22:00:59 +0000 (22:00 +0000)
redirector

index fd8920c..74d3b58 100755 (executable)
@@ -1,9 +1,29 @@
-#! /bin/sh
+#! /usr/bin/perl
 #
 # $Id$
 
 #
 # $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 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.=$_;
+       }
+close M4;
+
+select STDOUT;
+$|=1;
+
+while (<>) {
+       s@^http://($patt).*\n$@http://localhost/cgi-bin/redirector-ad.cgi?$1\n@os;
+       print;
+       }