#!/usr/local/bin/perl5 -T
#
# expand.cgi - A cgi script to take a master html file, and expand
# a given section, and return the file.
#
# The master html will contain bulleted lists (
) with sublists
# which are expandable/collapsable. We loop through the list,
# only expanded the requested portion.
#
# This nifty idea is due to Greg Atchity. The cgi implementation
# is by Alan Schwartz
$target = $ARGV[0];
$target =~ s/#.*//;
$target =~ s/[^\w\s\d]//g;
$master = '/home/alansz/www/rw-pbem/master.html';
$top = "/~alansz/rw-pbem/";
&header;
unless (open(IN,$master)) {
print "Sorry, can't.\n";
exit 0;
}
while () {
if (m#href\s*=\s*"(.*?)"#) {
$href = $1;
s#href\s*=\s*"([^/\#])#href="$top$1# unless $href =~ m#//#;
}
$current = $1 if $count == 1 && /\- .*name="([^"]*)"/i;
$count++ if /\
/i;
print unless ($count > 1 && $current !~ /$target/i);
$count-- if /\<\/ul\>/i;
}
&footer;
exit 0;
#-----------------------------------
sub header {
print <