#
# Generate a list of categories from the H3 headings.
#
# Constructs a list of letters to allow one to jump quickly to the first H3
# header category list that starts with that letter. This reduces the amount
# of scrolling when the category list gets long.
#
# Usage:
# perl showhead.pl
#
# Generates two files:
# mapindex.src - contains letters to jump to an entry in the site map.
# map.src - contains the map entries.
# These two files are intended to be part of a frame which uses the mapindex
# letters to jump to a map entry.
#
#------------------------------------------------------------------------------
use English;
use strict;
my %alpha;
my %titles;
my $name;
my @components;
my $n_components;
my $first;
my $second;
my @fields;
my $title;
my @unsorted_titles;
my $low_title;
my $ch;
my @titles;
my $html_code;
my $line;
# Generate the page header stuff for both files.
open(MAP, ">map.src");
open(MAPINDEX, ">mapindex.src");
print MAP '#include "common.inc"', "\n";
print MAPINDEX '#include "common.inc"', "\n";
print MAP "<HTML>\n";
print MAPINDEX "<HTML>\n";
print MAPINDEX "<BODY>\n";
print MAPINDEX "<BIG>Click on a minor category to go there.</BIG>\n";
print MAPINDEX "<P>\n";
print MAPINDEX '<BIG>Press a letter to jump down to that category.</BIG>', "\n";
print MAPINDEX '<P>', "\n";
# Loop through all of the HTML files looking for H3 headers.
$name = "/home/tom/ALL/WWW";
opendir(ALL, $name) || die "no $name";
%alpha = ();
%titles = ();
while ($name = readdir(ALL)) {
@components = split(/\./, $name);
$n_components = @components;
if ($n_components == 2) {
$first = $components[0];
$second = $components[1];
if (($second eq "HTM") || ($second eq "htm")){
open(FILE, $name);
while (<FILE>) {
chop;
if (/\<H3\>/i) {
@fields = split(/\"/, $_); # "
$title = $fields[1];
if ($title ne "") {
# Lowercase everything to make filenames consistent.
$name =~ tr/A-Z/a-z/;
# Save away the title and filename.
push (@unsorted_titles, $title . "\#" . $name);
# For a title that starts with a letter, if this title comes
# before the title that has been stored, use this title instead.
# The hash "alpha" contains the title in lower case (for
# comparison purposes) and the hash titles contains the original
# title.
$low_title = $title;
$low_title =~ tr/A-Z/a-z/;
$ch = substr($title, 0,1);
# Convert to upper case to make it look better.
$ch =~ tr/a-z/A-Z/;
if (($ch ge "A") && ($ch le "Z")) {
if (($alpha{$ch} eq "") || ($low_title lt $alpha{$ch})) {
### if (($alpha{$ch} eq "") || ($title lt $titles{$ch})) {
$alpha{$ch} = $low_title;
$titles{$ch} = $title;
}
}
}
}
}
close(FILE, $name);
}
}
}
closedir(ALL);
# Generate a list of the letters that allows one to jump to a category.
foreach $ch (sort keys %alpha) {
print MAPINDEX '<A HREF="map.htm#' . $titles{$ch} . '" TARGET="MAP">' .
$ch . '</A>', "\n";
}
# Now generate the list of categories, each one in a list item (LI).
@titles = sort {lc($a) cmp lc($b)} @unsorted_titles;
foreach $line (@titles) {
@fields = split(/\#/, $line);
$html_code = '<LI><A HREF="' . $fields[1] . '#' . $fields[0] . '" '
. 'NAME="' . $fields[0] . '" TARGET="_parent">' . $fields[0] . '</A>';
print MAP "$html_code\n";
}
# Now generate the trailer stuff for the page, including the <BACK> button to
# go back to the home page.
print MAP '<P>', "\n";
print MAP '<A HREF="index.html" TARGET="_parent">', "\n";
print MAP '<img src="back.gif" border="black"> Back to SITE_NAME home page</A>', "\n";
print MAP "<P><P>\n";
print MAP "</BODY>\n";
print MAP "</HTML>\n";
print MAPINDEX '  ', "\n";
print MAPINDEX '<A HREF="index.html" TARGET="_parent">', "\n";
print MAPINDEX '<img src="back.gif" border="black"> Back to SITE_NAME home page</A>', "\n";
print MAPINDEX "</BODY>\n";
print MAPINDEX "</HTML>\n";
close MAP;
close MAPINDEX;
Back to The Information Cave home page
Last modified Mon Apr 26 20:52:19 1999.