#!/usr/local/bin/perl require "common.pl"; $webmaster = "Shishir Gundavaram (shishir\@bu\.edu)"; $fgrep = "/usr/local/bin/fgrep"; $document_root = $ENV{'DOCUMENT_ROOT'}; &parse_form_data (*SEARCH); $query = $SEARCH{'query'}; if ($query eq "") { &return_error (500, "Search Error", "Please enter a search query."); } elsif ($query !~ /^(\w+)$/) { &return_error (500, "Search Error", "Invalid characters in query."); } else { print "Content-type: text/html", "\n\n"; print "", "\n"; print "Search Results"; print "
Полезная информация

", "\n"; print "

Results of searching for: ", $query, "

"; print "
"; open (SEARCH, "$fgrep -A2 -B2 -i -n -s $query $document_root/* |"); $count = 0; $matches = 0; %accessed_files = (); while () { if ( ($file, $type, $line) = m|^(/\S+)([\-:])\d+\2(.*)| ) { unless ($count) { if ( defined ($accessed_files{$file}) ) { next; } else { $accessed_files{$file} = 1; } $file =~ s/^$document_root\/(.*)/$1/; $matches++; print qq|$file

|; } $count++; $line =~ s/<(([^>]|\n)*)>/<$1>/g; if ($line =~ /^[^A-Za-z0-9]*$/) { next; } if ($type eq ":") { $line =~ s/($query)/$1<\/B>/ig; } print $line, "
"; } else { if ($count) { print "
"; $count = 0; } } } print "

", "


"; print "Total number of files searched: ", $matches, "
"; print "
"; print "
", "\n"; close (SEARCH); } exit (0);