#!/usr/bin/perl -w use strict; use Pod::Html; use File::Basename; use vars qw/$TMPFILE/; $TMPFILE='split-temp.html'; die <<"USAGE" unless @ARGV == 2; usage: $0 cssfile podfile USAGE die "$!" unless -f $ARGV[1]; pod2html( -noindex, $ARGV[1], -outfile=>$TMPFILE); my ($basename) = fileparse($ARGV[1],qw(.pod .pl .pm)); print "$ARGV[1] => $basename\n"; unless (-d $basename) { mkdir $basename or die "error creating $basename: $!"; } open ORIG,"<",$TMPFILE or die "Cannot open $TMPFILE for reading: $!"; my $orig = join('',); close ORIG; $orig =~ s/<\/PRE>\n
/\n/isg;

my @orig = map { "$_\n" } split(/\n/,$orig);


# build the index

warn "Building index data\n";

my %anchor2page;
my @titles;
my @subtitles;
my $i = 0;
for(@orig) {
#    print $_;

    if (/

]+>(.+?)<\/A>/) { $i++; $titles[$i] = $1; $subtitles[$i] = []; } if (/

(.+?)<\/A><\/H2>/) { push @{$subtitles[$i]},[$1,$2]; } if (/(.+?)<\/A>/) { $anchor2page{$1} = "$basename$i.shtml?#$1"; } s///ig; } warn "Building pages\n"; # loop over file again and make pages my $template = ''; my $csslink = qq( ); #get first part; while (@orig) { local $_ = shift @orig; $_ .= $csslink if /<\/HEAD>/i; $template .= $_; last if //; } $template .= qq{
\\X/ Web programming
}; while(@orig) { local $_ = shift @orig; last if /
/; } $i = 1; my $reallylast = 0; FILE: while (1){ warn "Building page $basename/$basename$i.shtml\n"; open NEWFILE,">","$basename/$basename$i.shtml" or die "Error creating $basename/$basename$i.shtml: $!"; print NEWFILE $template; my $filedata = ''; local $_; my $title; SECTION: while ($_ = shift @orig) { s/
//g; last SECTION if /
/; $reallylast = 1,last SECTION if /<\/BODY>/; $title = $_,next if /

/; $filedata .= $_; } my $navbar = "

"; $navbar .= "\"><< Prev section " if $i > 1; $navbar .= "\">Next section >>" unless $reallylast; $navbar .= "

"; my $index = "
"; for my $tnum (1 .. $#titles) { my $class = 'CLASS="leftnav"'; my $mainbul = 'bullet.gif'; if ($tnum == $i) { $class = 'CLASS="highlight"'; $mainbul = 'bullet2.gif'; } $index .= "\n"; if ($i == $tnum && $subtitles[$tnum]->[0]) { $class = 'CLASS="highlight2"'; for my $subtitle (@{$subtitles[$tnum]}) { $index .= "\n"; } } } $index .= qq( ); $index .= "
Index
\"\" width=8 height=16 border=0>\">$titles[$tnum]
\"\"\" width=8 height=16 border=0>#$subtitle->[0]\">$subtitle->[1]
"; print NEWFILE qq(
$index
$navbar$title$filedata$navbar
); close NEWFILE; $i++; last FILE if $reallylast; } print "OK\n"; exit; #### -- Joost downtime n. The period during which a system is error-free and immune from user input.