$title
Apache Documentation Search
This script performs a very simple search across the Apache
documentation for any single case-insensitive word. No combinations,
wildcards, regular expressions, word-stubbing, or other fancy options
are supported; this is just to help you find topics quickly. Only
those pages which include the exact word you type will be
listed.
Documents containing the search word are not listed in any
sort of priority order.
EOHT
printf ($HTML);
#
# Now set up the next section, which is only displayed if we've been
# given a word to find.
#
$HTML = <
Results of Search for $word
EOHT
#
# We enblock the next section so problems can drop out to the common
# closure code.
#
QUERY:
{
if ($word) {
#
# Try and open the index file; complain bitterly if we can't.
#
if (! open (INDEX, "<$INDEX")) {
printf ("Can't find documentation index!");
last QUERY;
}
#
# Got it; display the search-results header.
#
printf ($HTML);
#
# Read the entire index in and turn it into an hash for the
# lookup.
#
@index = ;
close (INDEX);
chomp (@index);
foreach (@index) {
($key, $files) = split (/:/, $_);
$Index{$key} = $files;
}
#
# The dictionary is all lowercase words. Smash our query value
# and try to find it.
#
$word = lc ($word);
if (! exists ($Index{$word})) {
printf (" \n Sorry, no matches found.\n
\n");
last QUERY;
}
#
# Found an entry, so turn the hash value (a comma-separated list
# of relative file names) into an array for display.
# Incidentally, tell the user how many there are.
#
@files = split (/,/, $Index{$word});
printf (" Total of %d match", scalar (@files));
#
# Be smart about plurals.
#
if (scalar (@files) != 1) {
printf ("es") ;
}
printf (" found.\n
\n");
#
# Right. Now display the files as they're listed.
#
printf (" \n");
foreach (@files) {
printf (" - ");
printf ("$_\n");
printf ("
\n");
}
printf ("
\n");
#
# C'est tout!
#
}
}
#
# Back to common code - the exit path. Display the page trailer.
#
$HTML = <
EOHT
printf ($HTML);
exit (0);