#!/usr/bin/perl # # prephtml - tidy up usman.html (generated by l2h from usman.tex). # Add page heading, table of contents etc. # $fname = $ARGV[0]; $quiet = 0; $singlePage = 1; $ext = "html"; $opp_version = "2.3"; # # general template for our output HTML pages; real contents will go to __BODY__ # $template = ' OMNeT++ - Manual

OMNeT++ Discrete Event Simulation System

__BODY__ '; # # read file into variable # print "reading $fname\n" unless $quiet; open( htmlf, $fname ) || die "cannot open $fname"; read( htmlf, $html, 1000000 ) || die "cannot read $fname"; # # kill unwanted formatting # print "removing unnecessary formatting and parts\n" unless $quiet; $html =~ s/ SIZE=2//g; $html =~ s/ FACE="[^"]*"//g; $html =~ s/ color=[a-z]*?//g; #$html =~ s/(\.*?\<\/H[0-9]\>)/\1<\/font>/g; # add IDs to headers $ctr=100; $html =~ s/(\)/$1.""/ge; # # Do some more LaTeX formatting, not done by L2H # $html =~ s/\$\^([^ ]*)\$/\$1\<\/sup\>/g; $html =~ s/\\chapter\*(.*)/\\$1\<\/b\>/g; $html =~ s/\\'([AEOUaeuo])/&$1acute;/g; $html =~ s/\\"([OUuo])/&$1uml;/g; $html =~ s/\\-//g; # # kill html header, title page, bad table of contents etc. # #$html =~ s/^(.*?)\/

/s; #$html =~ s/\<\/BODY\>.*$//s; ## ## add horiz bar before each H1 heading ## # $html =~ s/\/

/g; # # convert filenames in tags to lowercase # #$html =~ s/\"IMG([0-9]*)\.GIF\"/\"img$1.gif\"/g; # # collect heading info from document # print "collecting headings\n" unless $quiet; $scrap = $html; $i = 0; while ($scrap =~ s/\(.*?)\<\/H[0-9]\>//s) { $level[$i] = $1; $2 =~ m/\(.*)/s; $label[$i] = $1; $title[$i] = $2; $i++; } $nheadings = $i; # # calculate heading numbers # print "adding heading numbers\n" unless $quiet; for ($l=1; $l<10; $l++) {$hnum[$l]=0;} for ($i=0; $i<$nheadings; $i++) { # advance numbering $hnum[$level[$i]]++; for ($j=$level[$i]+1; $j<10; $j++) { $hnum[$j] = 0; } # assemble current heading number, e.g. "1.4.2." $number[$i] = ''; for ($j=1; $j<=$level[$i]; $j++) { $number[$i] .= $hnum[$j].'.'; } # store chapter number $chapnum[$i] = $hnum[1]; } # # insert numbers into manual body # for ($i=0; $i<$nheadings; $i++) { # search replace phrases like this: Expressions $html =~ s/(\)/\1$number[$i] /sg; } # # create 'chapters' table # print "creating Topics and TOC tables\n" unless $quiet; if ($singlePage) { $chapters = "

Chapters

\n"; } else { $navbar="


[Table of Contents]

"; $chapters = $navbar . "

OMNeT++ User Manual -- Chapters

\n"; } for ($i=0; $i<$nheadings; $i++) { if ($level[$i]==1) { $link = $singlePage ? "#toc_$number[$i]" : "chap$chapnum[$i].$ext"; $entry = "$number[$i] $title[$i]
"; $chapters .= "$entry\n"; } } # # create table of contents # if ($singlePage) { $toc = "

Table of Contents

\n"; } else { $navbar="


[Chapters]

"; $toc = $navbar . "

Table of Contents

\n"; } for ($i=0; $i<$nheadings; $i++) { $link = $singlePage ? "#$label[$i]" : "chap$chapnum[$i].$ext#$label[$i]"; $entry = "$number[$i] $title[$i]"; for ($j=0; $j<$level[$i]; $j++) {$entry = "  $entry";} if ($level[$i]==1) {$entry = "
$entry";} elsif ($level[$i]==2) {$entry = "$entry";} $toc .= "$entry
\n"; } if ($singlePage) { print "writing page\n" unless $quiet; $new_html = $template; $body = "

User Manual

OMNeT++ version $opp_version

$chapters
$toc$html"; $new_html =~ s/__BODY__/$body/; open(FILE,">usman.$ext"); print FILE $new_html; close FILE; } else { # # split up to chapters along H1 headings # print "splitting up to chapters\n" unless $quiet; $nchapters = 0; $scrap = $html; while ($scrap =~ s/(\.*?)\/\/s) { $chapter[++$nchapters] = $1; } $chapter[++$nchapters] = $scrap; # # create navigation bars for each chapter # for ($i=1; $i<=$nchapters; $i++) { $navbar[$i] = "


"; if ($i>1) {$t=$i-1; $navbar[$i] .= "[Prev]";} if ($i<$nchapters) {$t=$i+1; $navbar[$i] .= " [Next]";} $navbar[$i] .= " [TOC]"; $navbar[$i] .= " [Chapters]"; $navbar[$i] .= "

"; } # # write each chapter into a separate file # print "writing chapter files\n" unless $quiet; for ($i=1; $i<=$nchapters; $i++) { $new_html = $template; $new_html =~ s/__BODY__/$navbar[$i]$chapter[$i]$navbar[$i]/; open(FILE,">chap$i.$ext"); print FILE $new_html; close FILE; } # # write chapters file (usman.html) # print "writing chapters file\n" unless $quiet; $new_html = $template; $body = "

User Manual

OMNeT++ version $opp_version

$chapters"; $new_html =~ s/__BODY__/$body/; open(FILE,">usman.$ext"); print FILE $new_html; close FILE; # # write toc file (toc.html) # print "writing toc file\n" unless $quiet; $new_html = $template; $new_html =~ s/__BODY__/$toc/; open(FILE,">toc.$ext"); print FILE $new_html; close FILE; } print "done\n" unless $quiet;