home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 6 / AACD06.ISO / AACD / Online / Apache / htdocs / manual / search / manual-index.cgi
Text File  |  1999-02-25  |  7KB  |  247 lines

  1. #!/usr/local/bin/perl5 -w
  2. # ====================================================================
  3. # Copyright (c) 1995-1997 The Apache Group.  All rights reserved.
  4. #
  5. # Redistribution and use in source and binary forms, with or without
  6. # modification, are permitted provided that the following conditions
  7. # are met:
  8. #
  9. # 1. Redistributions of source code must retain the above copyright
  10. #    notice, this list of conditions and the following disclaimer. 
  11. #
  12. # 2. Redistributions in binary form must reproduce the above copyright
  13. #    notice, this list of conditions and the following disclaimer in
  14. #    the documentation and/or other materials provided with the
  15. #    distribution.
  16. #
  17. # 3. All advertising materials mentioning features or use of this
  18. #    software must display the following acknowledgment:
  19. #    "This product includes software developed by the Apache Group
  20. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  21. #
  22. # 4. The names "Apache Server" and "Apache Group" must not be used to
  23. #    endorse or promote products derived from this software without
  24. #    prior written permission.
  25. #
  26. # 5. Redistributions of any form whatsoever must retain the following
  27. #    acknowledgment:
  28. #    "This product includes software developed by the Apache Group
  29. #    for use in the Apache HTTP server project (http://www.apache.org/)."
  30. #
  31. # THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32. # EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  33. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34. # PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35. # ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42. # OF THE POSSIBILITY OF SUCH DAMAGE.
  43. # ====================================================================
  44. #
  45. # manual-index.cgi script
  46. # originally written by Ken Coar <Coar@DECUS.Org> in May 1997
  47. #
  48. # This script either displays a form in order to find documents in which
  49. # a word appears, or displays the results of such a search.  It is
  50. # called as a CGI script.
  51. #
  52. # [FILE]PATH_INFO is the prefix to add to to the files names found in
  53. # the index (URL prefix, not filesystem prefix), and QUERY_STRING is the
  54. # word to be found.
  55. #
  56. #***
  57. #***
  58. # You may need to tweak the following line to point to the correct
  59. # location of the index file on your system (it's in the
  60. # apache/htdocs/manual directory of the Apache distribution tree).
  61. #***
  62. #***
  63. $INDEX = "/www/apache.org/manual-index-data";
  64.  
  65. #***
  66. #***
  67. # You shouldn't have to modify anything else.
  68. #***
  69. #***
  70.  
  71. $HTML = "";
  72.  
  73. #
  74. # If we have a FILEPATH_INFO or PATH_INFO, it's there to remap the
  75. # documents to the manual root directory.  If this script is already in
  76. # that directory, this isn't needed.
  77. #
  78. $prefix = $ENV{'FILEPATH_INFO'} || $ENV{'PATH_INFO'};
  79. $prefix .= "/" if ($prefix && ($prefix !~ m:/$:));
  80.  
  81. #
  82. # QUERY_STRING, if present, contains the word for which we are to
  83. # search.  We also  use its [non]presence to determine wha we display.
  84. #
  85. $word = $ENV{'QUERY_STRING'};
  86.  
  87. #
  88. # Make sure our HTTP header makes it to the server by causing Perl to do
  89. # a fflush() after every write to STDOUT.
  90. #
  91. select (STDOUT);
  92. $| = 1;
  93. printf ("Content-type: text/html\n\n");
  94.  
  95. #
  96. # Fine, now buffering can go back to normal.
  97. #
  98. $| = 0;
  99.  
  100. #
  101. # Set up the HTML page title
  102. $title = "Apache Documentation Search";
  103. $title .= ": Results for \"$word\"" if ($word);
  104.  
  105. #
  106. # We'll re-use the HTML scalar several times; we use it with here
  107. # documents for multi-line static HTML code.  Lets' do the standard page
  108. # header.
  109. #
  110. $HTML = <<EOHT;
  111. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
  112. <HTML>
  113.  <HEAD>
  114.   <TITLE>$title
  115.   </TITLE>
  116.  </HEAD>
  117. <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
  118.  <BODY
  119.   BGCOLOR="#FFFFFF"
  120.   TEXT="#000000"
  121.   LINK="#0000FF"
  122.   VLINK="#000080"
  123.   ALINK="#FF0000"
  124.  >
  125.   <DIV ALIGN="CENTER">
  126.    <IMG
  127.     SRC="${prefix}images/sub.gif"
  128.     ALT=""
  129.    >
  130.   </DIV>
  131.   <H1 ALIGN="CENTER">
  132.    Apache Documentation Search
  133.   </H1>
  134.   <P>
  135.   This script performs a very simple search across the Apache
  136.   documentation for any single case-insensitive word.  No combinations,
  137.   wildcards, regular expressions, word-stubbing, or other fancy options
  138.   are supported; this is just to help you find topics quickly.  Only
  139.   those pages which include the <EM>exact</EM> word you type will be
  140.   listed.
  141.   </P>
  142.   <P>
  143.   Documents containing the search word are <EM>not</EM> listed in any
  144.   sort of priority order.
  145.   </P>
  146.   <ISINDEX PROMPT="Enter word to find and press ENTER: ">
  147. EOHT
  148.  
  149. printf ($HTML);
  150.  
  151. #
  152. # Now set up the next section, which is only displayed if we've been
  153. # given a word to find.
  154. #
  155. $HTML = <<EOHT;
  156.   <HR>
  157.   <H2>
  158.    Results of Search for <SAMP>$word</SAMP>
  159.   </H2>
  160. EOHT
  161.  
  162. #
  163. # We enblock the next section so problems can drop out to the common
  164. # closure code.
  165. #
  166. QUERY:
  167.     {
  168.     if ($word) {
  169.         #
  170.         # Try and open the index file; complain bitterly if we can't.
  171.         #
  172.         if (! open (INDEX, "<$INDEX")) {
  173.         printf ("Can't find documentation index!");
  174.         last QUERY;
  175.         }
  176.         #
  177.         # Got it; display the search-results header.
  178.         #
  179.         printf ($HTML);
  180.         #
  181.         # Read the entire index in and turn it into an hash for the
  182.         # lookup.
  183.         #
  184.         @index = <INDEX>;
  185.         close (INDEX);
  186.         chomp (@index);
  187.         foreach (@index) {
  188.         ($key, $files) = split (/:/, $_);
  189.         $Index{$key} = $files;
  190.         }
  191.         #
  192.         # The dictionary is all lowercase words.  Smash our query value
  193.         # and try to find it.
  194.         #
  195.         $word = lc ($word);
  196.         if (! exists ($Index{$word})) {
  197.         printf ("  <P>\n  <EM>Sorry, no matches found.</EM>\n  </P>\n");
  198.         last QUERY;
  199.         }
  200.         #
  201.         # Found an entry, so turn the hash value (a comma-separated list
  202.         # of relative file names) into an array for display.
  203.         # Incidentally, tell the user how many there are.
  204.         #
  205.         @files = split (/,/, $Index{$word});
  206.         printf ("  <P>Total of %d match", scalar (@files));
  207.         #
  208.         # Be smart about plurals.
  209.         #
  210.         if (scalar (@files) != 1) {
  211.         printf ("es") ;
  212.         }
  213.         printf (" found.\n  </P>\n");
  214.         #
  215.         # Right.  Now display the files as they're listed.
  216.         #
  217.         printf ("  <OL>\n");
  218.         foreach (@files) {
  219.         printf ("   <LI><A HREF=\"${prefix}$_\">");
  220.         printf ("<SAMP>$_</SAMP></A>\n");
  221.         printf ("   </LI>\n");
  222.         }
  223.         printf ("  </OL>\n");
  224.         #
  225.         # C'est tout!
  226.         #
  227.     }
  228.     }
  229.  
  230. #
  231. # Back to common code - the exit path.  Display the page trailer.
  232. #
  233. $HTML = <<EOHT;
  234.   <A
  235.    HREF="/"
  236.   ><IMG
  237.     SRC="/images/apache_home.gif"
  238.     ALT="Home"
  239.    ></A>
  240.   <HR>
  241.  </BODY>
  242. </HTML>
  243. EOHT
  244.  
  245. printf ($HTML);
  246. exit (0);
  247.