-#! /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 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;
+ }