#cgi script to create dynamic table of contents for dtSearch framesets #Author: Brooke Hanford, Copyright February 2005 use strict; use CGI::Carp qw( fatalsToBrowser ); #hard path for perl's use my $citydir = "d:/inetpub/wwwroot/public_html/ca/ColusaCounty"; #virtual path for html use my $citydir1 = "../../../ca/ColusaCounty"; my $Title = "Colusa County, California"; #change this to 3 to print down to the section level my $depth = 2; my $tree; #print the html header print < $Title

Click the the plus (+) or minus (-) symbols to expand or collapse the entries

ENDHTML #generate digest list programmatically my @stack; my $branch = -1; processDir($citydir, $citydir1 ); sub processDir { my $dir = shift; my $linkpath = shift; opendir (CITYDIR, $dir) or die ("Can't open '$citydir' directory"); my @allfiles = grep (!/(images|css|cgi)/, grep (!/^\.\.?$/, readdir CITYDIR)); closedir CITYDIR; my @charter = grep (/ch\.html/i, @allfiles); #print STDERR @allfiles; my @dirfiles = sort numerically grep (!/(index|Ch|CharterTOC|nt|nx|pf|form|options|nav_bar)\.htm/i, @allfiles); if (@charter == 1) { &openfile ("$citydir/$charter[0]", $charter[0], $linkpath); } foreach my $file (@dirfiles) { my $dirpath = "$dir/$file"; if ($file =~ /\.htm/ ) { &openfile ($dirpath, $file, $linkpath); } elsif( -d $dirpath) { next if $file =~ /\./; processDir( $dirpath, "$linkpath/$file"); } } } sub numerically { # 02 # 0210 my ($chap3, $chap4); $chap3 = $1 if $a =~ /colusacounty([^$\.]+)(?:\.html)?$/i; $chap4 = $1 if $b =~ /colusacounty([^$\.]+)(?:\.html)?$/i; if( $chap3 =~ m{^99} && $chap4 !~ m{^99} ) { return 1; } elsif( $chap3 !~ m{^99} && $chap4 =~ m{^99} ) { return -1; } if ($chap3 && $chap4) { return $chap3 <=> $chap4; } elsif ($chap3) { return 1; } elsif ($chap4) { return -1; } else { return $a cmp $b; } } printBuffer(); #open EndToc.html to include static end of file info while( @stack >= 1 ) { pop @stack; print "
\n"; } print <
ENDFILE #end of html code #subroutines sub openfile { my $dir = shift if @_; my $htmfile = shift if @_; my $linkpath = shift if @_; open (FILE, "$dir") or die ("Can't open file '$dir'"); my @htmfilecontents = ; close FILE; my @titlename = grep (/# #gi; if ( $titlename[$i] =~ m{[^<]+)}{} ) { $updated = $1; } $titlename[$i] =~ s#<[^>]+>##gi; $titlename[$i] =~ s#\*##gi; $titlename[$i] =~ s#^ ##gi; $titlename[$i] =~ s#\n##gi; my $titleno; if ( $titlename[$i] =~ m~Title ([IVX]+)[ \t]~ig ) { $titleno = $1; } if( $level == 1) { if( defined( $tree->{1} ) ) { printBuffer(); } push @stack, (1); $tree->{1}->{text} = "$titlename[$i]"; } elsif ($level == 2) #chapters { $branch++; push @stack, (1); if( $updated ) { $tree->{1}->{children}->[$branch]->{text} = "$titlename[$i] $updated"; $updated =~ s/Added/Revised/; $tree->{1}->{text} .= " $updated" unless $tree->{1}->{text} =~ m{$}; $updated = 0; } else{ #print STDERR $titlename[$i] . ":: $anchor\n"; $tree->{1}->{children}->[$branch]->{text} = "$titlename[$i]"; } } elsif( $level == 3) #everything else: OT, CH, etc { if( $updated ) { push @{$tree->{1}->{children}->[$branch]->{children} }, "$titlename[$i] $updated"; $updated =~ s/Added/Revised/; $tree->{1}->{children}->[$branch]->{text} .= " $updated" unless $tree->{1}->{children}->[$branch]->{text} =~ m{$}; $tree->{1}->{text} .= " $updated" unless $tree->{1}->{text} =~ m{$}; $updated = 0; } else { push @{$tree->{1}->{children}->[$branch]->{children} }, "$titlename[$i]" if $branch > -1; } } } } #end sub sub printBuffer { if( defined($tree->{1}->{children} ) ){ print "

+ $tree->{1}->{text}

\n
\n"; foreach my $chapter ( @{$tree->{1}->{children} } ) { if($depth == 3 && defined($chapter->{children} ) ){ print "

+ $chapter->{text}

\n
\n"; foreach my $section ( @{$chapter->{children} } ) { print "

• $section

"; } print "
"; } else { print "

– $chapter->{text}

\n"; } } print "
"; } else { print "

– $tree->{1}->{text}

\n\n"; } $tree = undef; $branch = -1; }