home *** CD-ROM | disk | FTP | other *** search
/ ftp.sunet.sepub/pictures / 2014.11.ftp.sunet.se-pictures.tar / ftp.sunet.se / pub / pictures / ACiD-artpacks / www / mirrors / acheron / cgi-bin / vision_Search.cgi < prev    next >
Text File  |  1999-01-24  |  24KB  |  619 lines

  1. #!/usr/bin/perl
  2.  
  3. #########################################################################
  4. #site Search
  5. #Version 2.00b
  6. #copyright  1997-1998 Krishnan Jayakrishnan.
  7. #All Rights Reserved
  8. #------------------------------------------------------------------------
  9. #copyright Notice:-
  10. #site Search is a shareware program and may be used , modified or
  11. #distributed  by anyone free of charge. site Search is provided on an
  12. #"as-is" basis and Krishnan Jayakrishnan makes no warranties either
  13. #expressed or implied with respect to the software's merchantablity or
  14. #fitness for any particular purpose. By using site Search, you agree to
  15. #indemnify Krishnan Jayakrishnan from any and all incidental or
  16. #consequential damages that may arise from its use. Please obtain a
  17. #written permission before selling this program.In all cases this
  18. #copyright Notice  must remain intact.
  19. #------------------------------------------------------------------------
  20. #Contact information
  21. #krishnan@bayou.uh.edu
  22. #
  23. #Krishnan . J
  24. #Allied Geophysical Labs
  25. #University of Houston
  26. #Houston TX77204-4231
  27. #------------------------------------------------------------------------
  28. #Version History
  29. #Intial Release on September 17th 1997                  Version 1.00
  30. #2nd Release on September 23rd 1997                     Version 1.01
  31. #3rd Release on September 25th 1997                     Version 1.02
  32. #4th Release on January 21nd 1998                         Version 2.00b
  33. #
  34. #The latest version is available at http://www.agl.uh.edu/~saljxk/site_Search
  35. #------------------------------------------------------------------------
  36. #Thanks To,
  37. #
  38. #B. G. Mahesh (www.mahesh.com),
  39. #Darron Hutchison (tm)(www.webmakers.com.au),
  40. #Cinnamon Chu, Tina Ma, 
  41. #Bob Lenaerts, Patrice Serrano, 
  42. #V.A.
  43. #------------------------------------------------------------------------
  44.  
  45.  
  46. open(READ,"vision_Search.conf ") or &Error_Module("1");
  47. require("./vision_Search.conf");
  48. require ("cgi-lib.pl") or &Error_Module("2");
  49.  
  50. $version = "2.00b";
  51. @months = (January,February,March,April,May,June,July,August,September,October,November,December);
  52.  
  53. &Check_Configurations    if($check_script eq "1");
  54. &Clean_Scratch          if($clean_scratch eq "1");
  55. &Get_Search_Terms;
  56. &Get_Files_to_Search    if($skip_search ne "1");
  57. &Search_Files;
  58. &Display_Results1 if ((scalar(@file_names_to_display) == 0) ||
  59.                 (scalar(@file_names_to_display) <= int($get_hits)) ||
  60.                 ($get_hits =~ /all/i) ||
  61.                 ($get_hits eq "") ||
  62.         ($multi_display eq "0"));
  63.         
  64. &Display_Results2;
  65.  
  66. #        -:PRIMARY MODULES:-            #
  67. #########################################################
  68. #    Module Checks for errors in configuration file    #
  69. #########################################################
  70. sub Check_Configurations{
  71. print &Header;
  72.  
  73. &Error_Module("3")    if(!(-r "site_Search.desc") && ($desc1 eq "1"));
  74. &Error_Module("4")    if(!(-d "$base_path") || !(-r "$base_path"));
  75. &Error_Module("5")    if(scalar(@filetypes) == 0);   
  76.  
  77. if ($multi_display eq "1"){
  78. &Error_Module("6")    
  79.     if(($scratch eq "") || !(-d "$base_path/$scratch") || !(-w "$base_path/$scratch") || !(-r "$base_path/$scratch"));
  80. }
  81.  
  82. if ($record_usage eq "1"){
  83. &Error_Module("7")    if ((-e "site_Search.usage") && !(-w "site_Search.usage"));
  84. }
  85.  
  86. &Error_Module("8")    if ($path_to_searchform eq "");
  87. &Error_Module("9")    if ((($output_form eq "1") && ($form_to_use !~ /\binternal\b/)) && !(-r "$form_to_use"));
  88.  
  89. ($name_of_URI = "http:\/\/" . $ENV{'HTTP_HOST'}) if (length($name_of_URI) == 0);
  90.  
  91. print
  92.  
  93. "<P>No errors were Found. However, the script only runs a simple check through the configuration file.
  94. If you notice the script not working as intended please go through the files,
  95. <BR><BR><STRONG><LI>readme.html<BR><LI>FAQ.html<BR><BR></STRONG> before 
  96. sending me a mail (krishnan\@bayou.uh.edu).</P>
  97. <P>To run the script set the variable \"\$check_script\" to \"0\" in the configuration file.</P>"
  98. if ($errors ne "1");
  99. print &Bottom;
  100. die;
  101. }
  102.  
  103. #################################################
  104. #       Module Cleans the Scratch directory     #
  105. #################################################
  106. sub Clean_Scratch{
  107. my @list;
  108. @list = <$base_path/$scratch/[1-9]*.html>;
  109. $^T = time;
  110.  
  111. foreach (@list){
  112.         unlink($_) if (int(100*($age = -M)) > int(100*($empty_scratch)));
  113. }
  114. }
  115.  
  116. #################################################
  117. #         Module Parses the Form Output         #
  118. #################################################
  119. sub Get_Search_Terms{
  120.         
  121. &ReadParse(*input);
  122. $search_terms = ($input{'Searchterms'});
  123. @get_search_terms = split(/ /,$search_terms);
  124. $get_case = ($input{'Case'});
  125. $get_construct = ($input{'Construct'});
  126.  
  127. if (defined $input{'OUTPUT_FORM'}){
  128.     $skip_search = $skip_hits = "1";
  129.     $get_hits = "ALL";
  130.     open(READ,$input{'List_File'});
  131.     @files_to_be_searched = <READ>;
  132. }
  133.  
  134.  
  135. $get_hits = ($input{'Hits'}) if ($skip_hits ne "1");
  136. &no_search_terms if (scalar(@get_search_terms) == 0);
  137. &record_usage if($record_usage eq "1");
  138. &get_desc if ($desc1 eq "1");
  139. }
  140.  
  141. #################################################
  142. #    Module Gathers the Files to be Searched    #
  143. #################################################
  144. sub Get_Files_to_Search{
  145. my $file;
  146.  
  147. @files_from_scandir = &scandir($base_path);
  148.  
  149.  
  150. foreach $file (@files_from_scandir){
  151.                 push(@files_from_scandir,&scandir($file)) if((-d $file) && (&dirs_avoid($file) ne "0"));
  152. }
  153.  
  154. foreach $file (@files_from_scandir){
  155.         push(@files_to_be_searched,$file) if((&scantype($file) == 1) && (&files_avoid($file) ne "0"));
  156. }
  157.  
  158. foreach $file (@files_to_include){
  159.         push(@files_to_be_searched,$file);
  160. }
  161. }
  162.  
  163. #################################################
  164. #    Module Searches Files for Search Term(s)   #
  165. #################################################
  166. sub Search_Files{
  167. my $count;
  168.  
  169. foreach $file_name (@files_to_be_searched){
  170.     my $file_match_y = 0;
  171.     my $str_length = 0;
  172.     $mod_time = (stat($file_name))[9];
  173.         $mod_time{$file_name} = &Get_Date;
  174.         open(READ,"$file_name");
  175.         my @file_chars = <READ>;
  176.         $file_to_search = join("",@file_chars);
  177.         $title_array{$file_name} = "$1"
  178.         if ($file_to_search =~ /<TITLE>([^>]+)<\/TITLE>/i);
  179.         $desc_array{$file_name} = "$1"
  180.         if (($file_to_search =~ /<[^>]*META[^>]+NAME\s*=[ "]*description[ "]+CONTENT\s*=\s*"(([^>"])*)"[^>]*>/i) && ($desc2 == "1"));
  181.     $file_to_search =~ s/<([^>])*>//gs;
  182.     @list_of_lines = split(/[.!?]/g,$file_to_search) if(($output_line eq "1") && ($smart eq "0"));
  183.         @list_of_lines = split(/[a-z]['")]*[.!?]+['")]*\s/g,$file_to_search) if(($output_line eq "1") && ($smart eq "1"));
  184.      $_ = $file_to_search;
  185.  
  186.     if ($get_construct eq "As a phrase"){
  187.             $get_search_terms = join(" ",@get_search_terms);
  188.         push(@file_names_to_display,$file_name) if (($count = /\b$get_search_terms\b/o)  && ($get_case eq "Sensitive"));
  189.         push(@file_names_to_display,$file_name) if (($count = /\b$get_search_terms\b/io)  && ($get_case eq "Insensitive"));
  190.             $line_array{$file_name} = &get_line(@list_of_lines) if  (($output_line eq "1") && ($count > 0));
  191.         $hits_array{$file_name} = &get_hits() if (($output_hits eq "1") && ($count > 0));
  192.     }
  193.     
  194.     if ($get_construct eq "Any search term"){
  195.          foreach $get_search_term (@get_search_terms)
  196.                         {
  197.         push(@file_names_to_display,$file_name) if (($count = /\b$get_search_term/) && ($get_case eq "Sensitive"));
  198.         push(@file_names_to_display,$file_name) if (($count = /\b$get_search_term/i) && ($get_case eq "Insensitive"));
  199.         last if($count > 0);    
  200.                         }
  201.                 $line_array{$file_name} = &get_line(@list_of_lines) if(($output_line eq "1") && ($count > 0));
  202.                 $hits_array{$file_name} = &get_hits() if (($output_hits eq "1") && ($count > 0));
  203.         }
  204.  
  205.     if ($get_construct eq "All search terms"){        
  206.                 $str_length = @get_search_terms;
  207.                 foreach $get_search_term (@get_search_terms){
  208.         $file_match_y++ if (($count = /\b$get_search_term/) && ($get_case eq "Sensitive"));
  209.         $file_match_y++ if (($count = /\b$get_search_term/i) && ($get_case eq "Insensitive"));
  210.         }
  211.             push(@file_names_to_display,$file_name) if ($file_match_y == $str_length);
  212.         $line_array{$file_name} = &get_line(@list_of_lines) if (($output_line eq "1") && ($count > 0));
  213.         $hits_array{$file_name} = &get_hits()  if (($output_hits eq "1") && ($count > 0));
  214.                 }
  215. }
  216.  
  217. #################################################
  218. #       Modules Display the Search Results      #
  219. #################################################
  220. sub Display_Results1{
  221. my $file_name;
  222.  
  223.         &No_Matches if (scalar(@file_names_to_display) == 0);
  224.         print &Header;
  225.         print &Top($title_for_search_page);
  226.         print "<CENTER>You searched for: <B><I>$search_terms</I></B>, returning ".@file_names_to_display." match(es)";
  227.         print "</CENTER><p>";
  228.                         
  229.         foreach $file_name (@file_names_to_display)
  230.         {
  231.                 my $file1 = substr($file_name,rindex($file_name,"/")+1);
  232.                 my $file2 = substr($file_name,length($base_path));
  233.                 my $mod_time = $mod_time{$file_name};
  234.  
  235.                 print "<A HREF=\"$name_of_URI$file2\"><B>$title_array{\"$file_name\"}</B></A> <font size=1><I>$mod_time</I></font><BR>";
  236.               #print " $desc_array{\"$file_name\"}<BR>" if (($desc1 eq "1") || ($desc2 eq "1"));
  237.               #print "$hits_array{\"$file_name\"}<BR>" if ($output_hits eq "1");
  238.                 print "$line_array{\"$file_name\"}" if ($output_line eq "1");
  239.                 print "<p>";
  240.            }
  241.         print "<BR>";
  242.         print "<CENTER><A HREF=\"$path_to_searchform\">[Search Again]</A></CENTER>";
  243.  
  244.     #print &output_form if ($output_form eq "1");
  245.     
  246.     print "<HR><A HREF=\"http://www.agl.uh.edu/~saljxk/site_Search\">
  247.     <FONT SIZE=-1>site Search Version $version copyright\©\; 1997, Krishnan Jayakrishnan</FONT></A>";
  248.     print &Bottom;
  249.     die;
  250. }
  251.  
  252. ### ... Module 2
  253. sub Display_Results2{
  254. my $counter = 0;
  255. my $counter2;
  256. my $files_displayed = 0;
  257. my $files_to_display = int($get_hits);
  258. my $output_fileno = 1;
  259. my $hits = int($get_hits);
  260.  
  261.     while($counter < scalar(@file_names_to_display)){
  262.         if($files_displayed == 0){
  263.             print &Header;
  264.             $output = "STDOUT";
  265.             $next_file = $$ . "_$output_fileno" . "_of_" . "$hits" . ".html";
  266.             }else{
  267.             $output = "WRITE";
  268.             open(WRITE,">$base_path/$scratch/$next_file");
  269.             $output_fileno++;
  270.             $next_file = $$ . "_$output_fileno" . "_of_" . "$hits" . ".html";
  271.             }
  272. print $output &Top($title_for_search_page);
  273. print $output "<B>You searched for: <I>$search_terms</I>, returning ";
  274. print $output "".scalar(@file_names_to_display)."  Match(es)</B><BR>";
  275. print $output "<P>Match(es) " . ($files_displayed+1) . " to " . ($files_displayed+$hits) . " </P>"
  276.         if (($counter + $hits) < scalar(@file_names_to_display));
  277. print $output "<P>Match(es) " . ($files_displayed+1) . " to " . scalar(@file_names_to_display) . " </P>"
  278.         if (($counter + $hits) > scalar(@file_names_to_display));
  279. print $output "</CENTER>";
  280. print $output "<FORM METHOD=\"GET\" ACTION=\"$name_of_URI/$scratch/$next_file\">" 
  281.         if (($counter + $hits) < scalar(@file_names_to_display));
  282.  
  283.          for($counter2 = $files_displayed;$counter2 < $files_to_display;$counter2++)
  284.                 {
  285.                         last if(length($file_names_to_display[$counter2]) == 0);
  286.                         $file1 = substr($file_names_to_display[$counter2],rindex($file_names_to_display[$counter2],"/")+1);
  287.                         $file2 = substr($file_names_to_display[$counter2],length($base_path));
  288.                         $mod_time = $mod_time{$file_names_to_display[$counter2]};
  289.         print $output "<A HREF=\"$name_of_URI$file2\"><B>$title_array{\"$file_names_to_display[$counter2]\"}</B></A> <font size=1><I>$mod_time</I></font><BR>";
  290.             #print $output "$desc_array{\"$file_names_to_display[$counter2]\"}<BR>" 
  291.             #        if (($desc1 eq "1") || ($desc2 eq "1"));
  292.             #print $output "$hits_array{\"$file_names_to_display[$counter2]\"}<BR>" if ($output_hits eq "1");
  293.                     print $output "$line_array{\"$file_names_to_display[$counter2]\"}" if ($output_line eq "1");
  294.         print $output "<p>";
  295.              
  296.                 }
  297.  
  298.         print $output "<P><CENTER><INPUT TYPE=\"SUBMIT\" VALUE=\"Display next $hits matches >>\"></CENTER></P>"
  299.         if (($counter + $hits) < scalar(@file_names_to_display));
  300.  
  301.         print $output "<BR><CENTER><A HREF=\"$path_to_searchform\">[Search Again]</A></CENTER>";
  302.         print $output "</FORM>";
  303.  
  304.         #print $output &output_form if ($output_form eq "1");
  305.  
  306.         print $output "<A HREF=\"http://www.agl.uh.edu/~saljxk/site_Search\">
  307.         <FONT SIZE=1>site Search Version $version copyright\©\; 1997, Krishnan Jayakrishnan</FONT></A>";
  308.         print $output &Bottom;
  309.  
  310.     $files_displayed += $hits;
  311.     $counter += $hits;
  312.     $files_to_display += $hits;
  313. }
  314. }
  315.  
  316. #########################################################
  317. #        -:SECONDARY MODULES:-            #
  318. #########################################################
  319. #___Module Prints Error Messages to Help Rectify___#
  320. sub Error_Module
  321. {
  322.         $errors = "1";
  323.         print &Header if ($_[0] eq "1");
  324.         print "<FONT SIZE=\"3\" FACE=\"HELVETICA\"><BR>";
  325.         print "<P> A Configuration file <STRONG> site_Search.conf </STRONG> could not be located in the current<BR>
  326.                 directory, either the file is not present or does not have read permissions. To get help rectifying<BR>
  327.                 the error, read the \"Errors\" section, (Error-1) of the \"readme.html\" file.<BR>" if ($_[0] eq "1");
  328.         print "<P> Could not load the cgi-lib.pl library. To get help rectifying the error, read<BR>
  329.                 read the \"Errors\" section, (Error-2) of the \"readme.html\" file.<BR>"     if ($_[0] eq "2");
  330.         print "<P> The description file <STRONG> site_Search.desc </STRONG> could not be opened for reading. There<BR>
  331.                 could be a permission problem. To get help rectifying the error, read the \"Errors\" section, (Error-3) of<BR>
  332.                 of the \"readme.html\" file.<BR>"                         if ($_[0] eq "3");
  333.         print "<P> There is a problem with the base-path specified to start the search. To get help rectifying the error,<BR>
  334.                 read the \"Errors\" section, (Error-4) of the \"readme.html\" file.<BR>"     if ($_[0] eq "4");
  335.         print "<P> No filetypes have been specified to search. To get help rectifying the error, read the \"Errors\" section,<BR>
  336.                 (Error-5) of the \"readme.html\" file.<BR>"                     if ($_[0] eq "5");
  337.         print "<P> There is a problem with the scratch directory specified. To get help rectifying the error, read the <BR>
  338.                 \"Errors\" section, (Error-6) of the \"readme.html\" file.<BR>"         if ($_[0] eq "6");
  339.         print "<P> There is a problem recording the script usage. To get help rectifying the error, read the \"Errors\" <BR>
  340.                 section, (Error-7) of the \"readme.html\" file.<BR>"                 if ($_[0] eq "7");
  341.         print "<P> A HTTP Path to the search form was not specified. To get help rectifying the error, read the \"Errors\" <BR>
  342.                 section, (Error-8) of the \"readme.html\" file.<BR>"                 if ($_[0] eq "8");
  343.         print "<P> No Valid form was found at $form_to_use . To get help rectifying the error, read the \"Errors\" <BR>
  344.                 section, (Error-9) of the \"readme.html\" file.<BR>"                 if ($_[0] eq "9");
  345.         print "</FONT>";
  346.         print &Bottom;
  347.  }
  348.  
  349. #_____Module Returns the Output Document Type______#
  350. sub Header
  351. {
  352.         return "Content-type: text/html\n\n";
  353. }   
  354.  
  355. #_____Module Returns the Output Document Head_______#
  356. sub Top
  357. {
  358.         my ($title) = @_;
  359.         return <<"ENDPRINT";
  360. <HTML>
  361. <HEAD>
  362. <TITLE>visions | search results</TITLE>
  363. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  364. </HEAD>
  365.  
  366. <BODY BGCOLOR="#FFFFFF">
  367. <a name="top"></a> 
  368. <div align="center">
  369. <table border="0" width="614" cellspacing="0" cellpadding="0">
  370.   <tr> 
  371.           <td bgcolor="#cccccc">
  372.             
  373.       <table border="0" width="614" cellspacing="0" cellpadding="2">
  374.         <tr> 
  375.                 <td><font size="2" face="Arial, Helvetica, sans-serif"><b>vision 
  376.                   | </b>literature on the web</font></td>
  377.                 <td align="right"><font size="1" face="Arial, Helvetica, sans-serif"><a href="/vision/index.shtml">home</a> 
  378.       | <a href="/vision/index.shtml">latest</a> | <a href="/vision/archive/archive.shtml">archive</a> 
  379.       | <a href="/vision/members.shtml">members</a> | <a href="/vision/links.shtml">links</a> 
  380.       | <a href="/vision/search.shtml">search</a></font></td>
  381.               </tr></table></td></tr>
  382.  
  383.               <tr> 
  384.                 <td bgcolor="#000000"><img src="/vision/images/trans_dot.gif" width="1" height="1"></td>
  385. <td bgcolor="#000000"><img src="/vision/images/trans_dot.gif" width="1" height="1"></td>
  386.               </tr>
  387.         <tr>
  388.           <td>
  389.             
  390.       <table border="0" width="614" cellspacing="0" cellpadding="2">
  391.         <tr>
  392.                 
  393.           <td width="87%" bgcolor="#000000"><a href="link"><font color="#FFFFFF" size="2">Tatharina:</font><font face="Times New Roman, Times, serif" size="2" color="#FFFFFF"> 
  394.             "Small quote taken from one of her pieces (recent)...."</font></a> 
  395.             <font color="#FFFFFF"><font face="Times New Roman, Times, serif" size="3"><font size="1" face="Arial, Helvetica, sans-serif">(</font></font></font><font face="Times New Roman, Times, serif" size="3"><font size="1" face="Arial, Helvetica, sans-serif"><a href="javascript:rand_quote();" onMouseOver="window.status='Random Musings'; return true" onMouseOut="window.status=' '; return true"><font color="#cccccc">random 
  396.             quote</font></a></font></font><font color="#FFFFFF"><font face="Times New Roman, Times, serif" size="3"><font size="1" face="Arial, Helvetica, sans-serif">)</font> 
  397.             </font></font></td>
  398.                 
  399.           <td width="13%" bgcolor="#FFCC00" align="center"><b>
  400. n/a</b></td>
  401.               </tr>
  402.             </table>
  403.           </td>
  404.         </tr>
  405.           <tr> 
  406.                 <td bgcolor="#000000"><img src="/vision/images/trans_dot.gif" width="1" height="1"></td>
  407. <td bgcolor="#000000"><img src="/vision/images/trans_dot.gif" width="1" height="1"></td>
  408.               </tr>
  409.       </table>
  410.       <table background="/vision/images/bg.gif" border="0" width="614" cellspacing="0" cellpadding="0">
  411.         <tr>
  412.           <td><font face="Arial" size="2"><img src="/vision/images/header-smp.gif" width="614" height="100"><br><br>          
  413. ENDPRINT
  414. }
  415.  
  416. #_____Module Returns the Output Document Bottom______#
  417. sub Bottom
  418. {
  419.         return "</td></tr></table></td></tr></table></BODY></HTML>\n";
  420. }
  421.  
  422. #____Module Scans Directories for all Files_____#
  423. sub scandir   
  424. {
  425.         $directory_to_scan = ($_[0]);
  426.         return(<$directory_to_scan/*>);
  427. }
  428.  
  429. #__Module Returns Only Files of Specified Type__#
  430. sub scantype
  431. {       
  432.         foreach $type (@filetypes){
  433.                 return 1 if((rindex $_[0], $type) >= 0);
  434.         }
  435. }
  436.  
  437. #____Module Checks for Validity of Directory____#
  438. sub dirs_avoid
  439. {
  440. my $check_dir = ($_[0]);
  441. my $dir; 
  442.  
  443.         foreach $dir (@directories_to_avoid){
  444.                 return 0 if($dir eq $check_dir);
  445.         }
  446. }       
  447.  
  448. #______Module Checks for Validity of File______#
  449. sub files_avoid
  450. {
  451. my $check_file = ($_[0]);
  452. my $file;
  453.  
  454.         foreach $file (@files_to_avoid){
  455.                 return 0 if($file  eq $check_file);
  456.         }
  457. }
  458.  
  459. #_Module Prints Message if no Search Terms are Entered_#
  460. sub no_search_terms{
  461. print &Header;
  462. print &Top("No Search Terms Entered");
  463.  
  464. print<<"ENDPRINT";
  465.         <CENTER><BR><P>No search terms were entered for search.
  466.     Please use your browser's <B>back</B> button to go back to the form and search again or do a
  467.         <A HREF="$path_to_searchform">New Search.</A></P></CENTER><HR>
  468.         <FONT SIZE=-1>
  469.     <A HREF=\"http://www.agl.uh.edu/~saljxk/site_Search\"><FONT SIZE=-1>
  470.         site Search Version $version copyright\©\; 1997, Krishnan Jayakrishnan<FONT></A>
  471. ENDPRINT
  472. print &Bottom;
  473. die;
  474. }
  475.  
  476. #_________Module Records Script Usage___________#
  477. sub record_usage{
  478.         open(WRITE,">>site_Search.usage");
  479.         $date = scalar localtime;
  480.         chomp($date);
  481.         print WRITE $date ."|".$ENV{'REMOTE_ADDR'}."|".$ENV{'REMOTE_HOST'}."|"."$search_terms\n";
  482.         close(WRITE);
  483. }
  484.  
  485. #_________Module Gathers Descriptions___________#
  486. sub get_desc{
  487. my $file_name;
  488. my $description;
  489.  
  490. open(READ,"site_Search.desc");
  491. while(<READ>){
  492.     ($file_name,$description) = split(/[sep]/,$_);
  493.     $desc_array{"$file_name"} = "$description";
  494. }
  495. }
  496.  
  497. #_______Module Returns the File Mod_Date________#
  498. sub Get_Date{
  499.         $mod_time = time unless ($mod_time);
  500.         ($day,$month,$year) = (localtime($mod_time))[3,4,5];
  501.         $date = "$day $months[$month] 19$year";
  502.         return $date;
  503. }
  504.         
  505. #_Module Returns the Line with the Search Term(s)_#
  506. sub get_line{
  507. my @array = @_;
  508. my $line;
  509. my $count = 0;
  510. my $sub_count = 0;
  511. my $search_term;
  512.  
  513. if ($get_construct eq "As a phrase"){
  514.         foreach $line (@array){
  515.                 $_ = $line;
  516.                  $count++;
  517.            $sub_count = s/\b$get_search_terms\b/\<B\>\<FONT COLOR=\"\#CCCCCC\"\>$get_search_terms\<\/FONT\>\<\/B\>/ig;
  518.                 return  "<FONT SIZE=\"2\" FACE=\"HELVETICA\">$array[$count-2].$_.$array[$count]</FONT><BR>" if ($sub_count > 0 );
  519.                 }
  520. }
  521. foreach $line (@array){
  522.     foreach $search_term (@get_search_terms){
  523.                 $_ = $line;
  524.                 $count++;
  525.                 $sub_count = s/\b$search_term\b/\<B\>\<FONT COLOR=\"\#CCCCCC\"\>$search_term\<\/FONT\>\<\/B\>/ig;
  526.                 return  "<FONT SIZE=\"2\" FACE=\"HELVETICA\">$array[$count-2].$_.$array[$count]</FONT><BR>" if ($sub_count > 0 );
  527.                 }
  528. }
  529. }
  530.  
  531. #_________Module Returns the no of Hits__________#
  532. sub get_hits{
  533. $_ = $file_to_search;
  534. my @hits;
  535. my $hits;
  536. my $search_term;
  537. my $line;
  538. my @lines;
  539.  
  540. if ($get_construct eq "As a phrase"){
  541.     ((@hits) = /\b$get_search_terms\b/og)  if ($get_case eq "Sensitive");
  542.         ((@hits) = /\b$get_search_terms\b/iog) if ($get_case eq "Insensitive");
  543.     $hits = int(scalar(@hits));
  544.     
  545.     return "<FONT SIZE=\"2\" FACE=\"HELVETICA\"><LI>$hits Occurence(s) of the search term <B>$get_search_terms</B></FONT><BR>";
  546. }
  547. foreach $search_term (@get_search_terms){
  548. ($hits = (@hits = /\b$search_term/g)) if ($get_case eq "Sensitive");
  549. ($hits = (@hits = /\b$search_term/ig)) if ($get_case eq "Insensitive");
  550. push(@lines,"<FONT SIZE=\"2\" FACE=\"HELVETICA\"><LI>$hits  occurence(s) 
  551. of the search term <B>$search_term</B> </FONT>"); 
  552. }
  553.  
  554. $line = join("",@lines);
  555. return $line."<BR>";
  556. }
  557.  
  558. #__Module Prints a Message if no Matches are Found___#
  559. sub No_Matches
  560. {
  561. print &Header;
  562. print &Top("No Matches Found");
  563.                 
  564. print "<CENTER>Case:$get_case | Construct:$get_construct | Hits Per Page:$get_hits | Terms:$search_terms</CENTER><BR><BR>";
  565.         print<<"ENDPRINT";
  566.         <CENTER><BR><P>No successful matches were found after the search.
  567.     Please use your browser's <B>back</B> button to go back to the form and search again or do a
  568.         <A HREF="$path_to_searchform">New Search.</A></P></CENTER><HR>
  569.         <A HREF=\"http://www.agl.uh.edu/~saljxk/site_Search\"><FONT SIZE=-1>
  570.         site Search Version $version copyright\©\; 1997, Krishnan Jayakrishnan<FONT></A>
  571. ENDPRINT
  572. print &Bottom;
  573. die;
  574. }
  575.  
  576. #_Module Outputs a Form to Perform Additional Searches_#
  577. sub output_form{
  578. my $files = scalar(@file_names_to_display);
  579. my $list_of_files = $$ . "_list_" . ".html";
  580.  
  581. open(LIST,">$base_path/$scratch/$list_of_files");
  582.  
  583. foreach $file (@file_names_to_display){
  584. chomp($file);
  585. print LIST "$file\n";
  586. }    
  587. if ($form_to_use !~ /\binternal\b/){
  588. open(READFORM,"$form_to_use");
  589. @lines = <READFORM>;
  590. return @lines;
  591. }
  592.  
  593. return <<"ENDPRINT";
  594. <HR>
  595. <FORM METHOD="GET" ACTION="$program_to_use">
  596.  
  597. <B>$files</B> file(s) matching your search criteria found.<BR>
  598. Narrow the search by searching <B>$files File(s)?</B>
  599.  
  600. <DIV ALIGN=LEFT><INPUT TYPE="TEXT" SIZE=20 MAXLENGTH=100 NAME="Searchterms"></DIV>
  601. Case:<SELECT NAME="Case">
  602. <OPTION VALUE="Insensitive">Insensitive 
  603. <OPTION VALUE="Sensitive">Sensitive
  604. </SELECT>
  605. Construct:<SELECT NAME="Construct">
  606. <OPTION VALUE="As a phrase">As a Phrase
  607. <OPTION VALUE="Any search term">Any Search Term
  608. <OPTION VALUE="All search terms">All Search Terms
  609. </SELECT>
  610.  
  611. <DIV ALIGN=LEFT><INPUT TYPE="SUBMIT" NAME="SUBMIT" VALUE="Search"><INPUT TYPE="RESET" VALUE="Reset"> </DIV>
  612. <INPUT TYPE="HIDDEN" NAME="List_File" VALUE="$base_path/$scratch/$list_of_files">
  613. <INPUT TYPE="HIDDEN" NAME="OUTPUT_FORM" VALUE="OK">
  614. </FORM>
  615. ENDPRINT
  616. }
  617.  
  618.