#!/usr/bin/perl require "./search_config.pl"; # configuration &ReadParse(*in); $terms=$in{'terms'}; $file=$in{'file'}; $type=$in{'type'}; $case=$in{'case'}; $test=$in{'test'}; $root_ref=".."; $file =~ s/~amp/&/g; $file =~ s/~quot/"/g; $file =~ s/~gt/>/g; $file =~ s/~lt/"; # print "
$tmp-$path$file-$terms-"; print "
$tmp-$file-$terms-"; $blah=`ls $path$file`; print "
-$blah-"; exit; } $hfront=""; $hend=""; $blar=1; while () { if ($type eq "phrase") { # $term2=uc $terms; # $term2="$term2"; # $term2="$term"; # if ($case) { $_ =~ s/(\b)($terms)(\b)(?!(\/<>))/\1$hfront\2$hend\3/g; } # else { $_ =~ s/(\b)($terms)(\b)(?!(\/<>))/\1$hfront\2$hend\3/gi; } # if ($case) { $_ =~ s/(?!<[^>]+>)($terms)(?!(\/>))/\1$hfront\2$hend/g; } # else { $_ =~ s/(?!<[^>]+>)($terms)(?!(\/>))/\1$hfront\2$hend/gi; } # if ($case) { $_ =~ s/($terms)(?!(\/>))/$hfront\1$hend/g; } # else { $_ =~ s/($terms)(?!(\/>))/$hfront\1$hend/gi; } if (!$test) { # 1 take everything that matches terms that are in a tag somewhere <..> and replaced it with something else # that will not get matched by those not in tags # 2 change text that matches terms # 3 change the first items back to normal if ($case) { $_ =~ s/(<[^>]*)$terms([^>]*>)/\1--XYZZY--\2/g; $_ =~ s/($terms)/$hfront\1$hend/g; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$terms\2/g; } else { $_ =~ s/(<[^>]*)$terms([^>]*>)/\1--XYZZY--\2/gi; $_ =~ s/($terms)/$hfront\1$hend/gi; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$terms\2/gi; } } else { # 1 take everything that matches terms that are in a tag somewhere <..> and replaced it with something else # that will not get matched by those not in tags # 2 change text that matches terms # 3 change the first items back to normal if ($case) { $_ =~ s/(<[^>]*)$terms([^>]*>)/\1--XYZZY--\2/g; $_ =~ s/($terms)/$hfront\1$hend/g; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$terms\2/g; } else { $_ =~ s/(<[^>]*)$terms([^>]*>)/\1--XYZZY--\2/gi; $_ =~ s/($terms)/$hfront\1$hend/gi; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$terms\2/gi; } } } else { foreach $term (@terms) { # $term2=uc $term; # $term2="$term2"; # $term2="$term"; # if ($case) { $_ =~ s/(\b)($term)(\b)(?!(\/<>))/\1$hfront\2$hend\3/g; } # else { $_ =~ s/(\b)($term)(\b)(?!(\/<>))/\1$hfront\2$hend\3/gi; } # if ($case) { $_ =~ s/(?!<[^>]+>)($term)(?!(\/>))/\1$hfront\2$hend/g; } # else { $_ =~ s/(?!<[^>]+>)($term)(?!(\/>))/\1$hfront\2$hend/gi; } # if ($case) { $_ =~ s/($term)(?!(\/>))/$hfront\1$hend/g; } # else { $_ =~ s/($term)(?!(\/>))/$hfront\1$hend/gi; } if (!$test) { # 1 take everything that matches terms that are in a tag somewhere <..> and replaced it with something else # that will not get matched by those not in tags # 2 change text that matches terms # 3 change the first items back to normal if ($case) { $_ =~ s/(<[^>]*)$term([^>]*>)/\1--XYZZY--\2/g; $_ =~ s/($term)/$hfront\1$hend/g; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$term\2/g; } else { $_ =~ s/(<[^>]*)$term([^>]*>)/\1--XYZZY--\2/gi; $_ =~ s/($term)/$hfront\1$hend/gi; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$term\2/gi; } } else { # 1 take everything that matches terms that are in a tag somewhere <..> and replaced it with something else # that will not get matched by those not in tags # 2 change text that matches terms # 3 change the first items back to normal if ($case) { $_ =~ s/(<[^>]*)$term([^>]*>)/\1--XYZZY--\2/g; $_ =~ s/($term)/$hfront\1$hend/g; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$term\2/g; } else { $_ =~ s/(<[^>]*)$term([^>]*>)/\1--XYZZY--\2/gi; $_ =~ s/($term)/$hfront\1$hend/gi; $_ =~ s/(<[^>]*)--XYZZY--([^>]*>)/\1$term\2/gi; } } } } $_ =~ s/(src=")/\1$pth/gi; $_ =~ s/(href=")(?!#)/\1$pth/gi; $_ =~ s/(href=")(?:#)/\1$file#\2/gi; print $_; } sub ReadParse { local $a = $_[0] ? $_[0] : \%in; local $i; if ($ENV{'REQUEST_METHOD'} eq 'POST') { read(STDIN, $in, $ENV{'CONTENT_LENGTH'}); } else { $in = $ENV{'QUERY_STRING'}; } @in = split(/\&/, $in); foreach $i (@in) { local ($k, $v) = split(/=/, $i, 2); $k =~ s/\+/ /g; $k =~ s/%(..)/pack("c",hex($1))/ge; $v =~ s/\+/ /g; $v =~ s/%(..)/pack("c",hex($1))/ge; $a->{$k} = defined($a->{$k}) ? $a->{$k}."\0".$v : $v; } } sub PrintHeader { return "Content-type: text/html\n\n"; }