#!/usr/bin/perl -w #*********# # MODULES # #*********# use strict; no strict "subs"; no strict "refs"; use XML::Parser; use Getopt::Std; use Carp; use HTML::Entities; use vars qw($AUTOLOAD); #***********# # CONSTANTS # #***********# my %article = (create_date => '', revise_date => '', issuenum => '', abstract => '', title => '' ); my %author_dir = ('3d' => '', 'dhtml' => '', 'graphics' => 'greats/', 'html' => '', 'js' => '', 'perl' => 'tutorial/', 'xml' => '' ); #*********# # GLOBALS # #*********# my $pages = 0; my $pagecnt = 1; # get tutorial filename my %opts = (); getopt('f', \%opts); &usage unless $opts{f}; &usage unless -e $opts{f}; #***************************************************# # -Count the number of pages we have in the article # #***************************************************# # parser tutorial file and get page count my $p = new XML::Parser; $p->setHandlers(Start => \&pages); $p->parsefile($opts{f}) || die "Cannot parse $opts{f}: $!\n"; undef $p; print STDOUT "Found $pages pages\n"; open (STDERR, ">/dev/null"); select(STDERR); # -generate HTML, second pass # $p = new XML::Parser; # set handlers $p->setHandlers(Char => \&handle_char, Start => \&handle_start, End => \&handle_end); # get filename pased from the command line $p->parsefile($opts{f}) || die "Cannot parse $opts{f}: $!\n"; #*************# # SUBROUTINES # #*************# sub banner_ad_top { print <

HTML } sub banner_ad_bottom { print <

HTML } sub button_bar { my $label = "$author_dir{$article{'productname'}} $article{'issuenum'}"; $label =~ s#/##; # first page if ($pagecnt == 1) { print < home / experts / $article{'productname'} / $label HTML # page 2 - x } else { print < home / experts / $article{'productname'} / $label HTML } # print the page buttons for (my $i = 1; $i <= $pages; $i++) { my $filename = ($i == 1 ? "index.html" : "$i.html"); if ($i == $pagecnt) { print ""; } elsif ($i < $pagecnt) { print ""; print ""; } elsif ($i > $pagecnt) { print ""; print ""; } } print < HTML } sub footer { my $filename = shift; my $label = "$author_dir{$article{'productname'}} $article{'issuenum'}"; $label =~ s#/##; print <

http://www.internet.com

HTML } sub handle_char { my ($self,$text) = @_; # grab article header stuff if ($self->within_element("artheader")) { $article{create_date} .= $text if $self->current_element eq "date"; $article{revise_date} .= $text if $self->current_element eq "pubdate"; $article{issuenum} .= $text if $self->current_element eq "issuenum"; $article{title} .= $text if $self->current_element eq "title"; $article{abstract} .= $text if $self->current_element eq "abstract"; $article{productname} .= $text if $self->current_element eq "productname"; } # grab author stuff if ($self->within_element("author")) { $article{author_first} = $text if $self->current_element eq "firstname"; $article{author_last} = $text if $self->current_element eq "surname"; } # print character data encode_entities($text); print $text unless ($self->within_element('artheader') || $self->within_element('author') || $self->within_element('keywordset') || $self->within_element('legalnotice') || $self->within_element('abstract') ); } #sub handle_default { # encode_entities($_[1]); # print "$_[1]"; #} sub handle_end { &{"$_[1]_"}(@_); } sub handle_start { &{$_[1]}(@_); } sub pages { return $pages++ if $_[1] eq 'sect1'; } sub para { print "

"; } sub para_ { print "

\n"; } sub programlisting { print "
"; }
sub programlisting_ { print "
\n";} sub sect1 { my $filename = ($pagecnt == 1 ? "index.html" : "$pagecnt.html"); print STDOUT "Writing $filename\n"; open(FILE,">$filename") || die "Cannot open $filename: $!\n"; select(FILE); print < $article{'title'} HTML &banner_ad_top; print <

HTML &button_bar; print "
\n"; } sub sect1_ { my $filename = ($pagecnt == 1 ? "index.html" : "$pagecnt.html"); print <

HTML &button_bar; &banner_ad_bottom; &footer($filename); close(FILE); select(STDERR); $pagecnt++; } sub sect2 { } sub sect2_ { } sub title { my ($self, $el, %attribs) = @_; if ($self->within_element('sect2')) { print "

\n"; } elsif ($self->within_element('sect1')) { print "

$article{'title'}

\n"; print "

\n"; } } sub title_ { my ($self, $el) = @_; if ($self->within_element('sect2')) { print "

\n"; } elsif ($self->within_element('sect1')) { print "\n"; } } sub ulink { my ($self, $el, %attribs) = @_; my $url = $attribs{'href'}; print ""; } sub ulink_ { print ""; } sub usage { print "\nUsage: webref_generate.pl -f \n"; exit; } sub AUTOLOAD { my @args = @_; my $self = shift; my $type = ref($self) || croak "$self is not an object\n"; my $name = $AUTOLOAD; $name =~ s/.*://; # ignore if within these elements return if ($self->within_element('artheader') || $self->within_element('author') || $self->within_element('keywordset') || $self->within_element('legalnotice') || $self->within_element('abstract') ); # ignore if we are these elements return if ($args[1] eq 'article' || $args[1] eq 'abstract' || $args[1] eq 'artheader' ); if ($name =~ /_$/) { print ""; } else { print ""; } }