#!/usr/bin/perl $DocDescFile = shift unless defined($DocDescFile); $StartString = undef; $StopString = undef; $PreprocessComment = undef; $DocRoot = undef; $SourceRoot = undef; $CodeRoot = undef; @StripLine = (); @PreprocessLine = (); @PreprocessDocLine = (); $Package = undef; $PackageTitle = undef; $MainName = undef; $HtmlExtension = undef; $FontFace = 'Times'; $FontSize = 3; $TTFontSize = 3; $TitleFontSize = 4; $PackageAbstract = ''; %File = (); @File = (); die "Can not open $DocDescFile!" unless open(F,"<$DocDescFile"); LINES: while( ){ if( /^\s*$/ || #empty lines /^\s*\#/ ){ next } #comment lines if( /^\s*FontFace\s*=\s*\'(.*)\'\s*$/ ){ $FontFace = $1; next; } if( /^\s*FontSize\s*=\s*(.*)\s*$/ ){ $FontSize = $1; next; } if( /^\s*TTFontSize\s*=\s*(.*)\s*$/ ){ $TTFontSize = $1; next; } if( /^\s*TitleFontSize\s*=\s*(.*)\s*$/ ){ $TitleFontSize = $1; next; } if( /^\s*Default\s*=\s*\'(.*)\'\s*$/ ){ die "Default double defined" if defined($MainName); $MainName = $1; next; } if( /^\s*Html\s*=\s*\'(.*)\'\s*$/ ){ die "HtmlExtension double defined" if defined($HtmlExtension); $HtmlExtension = $1; next; } if( /^\s*StartString\s*=\s*\'(.*)\'\s*$/ ){ die "StartString double defined" if defined($StartString); $StartString = $1; next; } if( /^\s*StopString\s*=\s*\'(.*)\'\s*$/ ){ die "StopString double defined" if defined($StopString); $StopString = $1; next; } if( /^\s*PreprocessComment\s*=\s*\'(.*)\'\s*$/ || /^\s*PreprocessCommand\s*=\s*\'(.*)\'\s*$/ ){ die "PreprocessComment double defined" if defined($PreprocessComment); $PreprocessComment = $1; next; } if( /^\s*DocRoot\s*=\s*\'(.*)\'\s*$/ ){ die "DocRoot double defined" if defined($DocRoot); $DocRoot = $1; next; } if( /^\s*SourceRoot\s*=\s*\'(.*)\'\s*$/ ){ die "SourceRoot double defined" if defined($SourceRoot); $SourceRoot = $1; next; } if( /^\s*CodeRoot\s*=\s*\'(.*)\'\s*$/ ){ die "CodeRoot double defined" if defined($CodeRoot); $CodeRoot = $1; next; } if( /^\s*StripLine\s*=\s*\'(.*)\'\s*$/ ){ push @StripLine,$1; next; } if( /^\s*PreprocessLine\s*=\s*\'(.*)\'\s*$/ ){ push @PreprocessLine,$1; next; } if( /^\s*PreprocessDocLine\s*=\s*\'(.*)\'\s*$/ ){ push @PreprocessDocLine,$1; next; } if( /^\s*Package\s*$/ ){ $Package = $1; while( ){ if( /^\s*End\s*$/ ){ next LINES; } if( /^\s*=title\s*(.*)$/ ){ $PackageTitle = $1; next; } if( /^\s*=H\s*(.*)$/ ){ $PackageTitle = $1; $_ = "H<$1>"; } $PackageAbstract .= $_; } } if( /^\s*Files\s*$/ ){ while( ){ if( /^\s*$/ || #empty lines /^\s*\#/ ){ next } #comment lines if( /^\s*End\s*$/ ){ next LINES; } if( /^\s*(.*)\s*=\s*(.*)\s*$/ ){ die "File $1 double defined." if defined( $File{$1} ); $File{$1} = $2; push @File,$1; } else { die "Bad format file definition:\n$_\n"; } } } die "Syntax error on line:\n$_\n"; } close F; $StartString = '=pod' unless defined($StartString); $StopString = '=cut' unless defined($StopString); $DocRoot = '.' unless defined($DocRoot); $SourceRoot = '.' unless defined($SourceRoot); $MainName = 'main' unless defined($MainName); $HtmlExtension = 'html' unless defined($HtmlExtension); if( ! -e $DocRoot ){ mkdir $DocRoot,0777; } if( defined($CodeRoot) && ! -e $CodeRoot ){ mkdir $CodeRoot,0777; } %mTitle = (); %mAbstract = (); while( ($file,$dir) = each %File ){ die "Can not read $SourceRoot/$file." unless open(F,"<$SourceRoot/$file"); $DoCommentStripping = 0; if( defined($CodeRoot) ){ if( open(OUT,">$CodeRoot/$file") ){ $DoCommentStripping = 1; }else{ warn "Can not write $CodeRoot/$file."; } } $sw = 0; $section = 'main'; %Body = (); %Title = (); %noToc = (); %Abstract = (); @section = (); %section = (); SOURCE_LINE: while( ){ chomp; if( $sw ){ if( $_ eq $StopString ){ $sw = 0; next; } for $command ( @PreprocessDocLine ){ eval $command; } eval $PreprocessComment; if( /\s*\=section\s*(.*)\s*/ ){ $section = $1; unless( $section{$section} ){ $section{$section} = 1; push @section,$section; } next; } if( /\s*\=notoc\s*$/ ){ $noToc{$section} = 1; next; } if( /\s*\=title\s*(.*)$/ ){ die "title for section $section in file $file is double defined" if defined($Title{$section}); $Title{$section} = $1; next; } if( /^\s*=H\s*(.*)$/ ){ die "title for section $section in file $file is double defined" if defined($Title{$section}); $Title{$section} = $1; $_ = "H<$1>"; } if( /\s*\=abstract\s*$/ ){ die "abstract for section $section in file $file is double defined" if defined($Abstract{$section}); $Abstract{$section} = ''; while( ){ chomp; die "abstract for section $section in file $file is not closed" if $_ eq $StopString; eval $PreprocessComment; if( /\s*\=end\s*$/ ){ next SOURCE_LINE; } $Abstract{$section} .= "$_\n"; } die "abstract for section $section in file $file is not closed till eof" if $_ eq $StopString; } $Body{$section} .= "$_\n"; }else{#we are outside of documentation lines $line = $_; s/\s*$//; if( $_ eq $StartString ){ $sw = 1; }else{ if( $DoCommentStripping ){ $_ = $line; for $command ( @PreprocessLine ){ eval $command; } my $strip = 0; for $command ( @StripLine ){ last if $strip = eval $command; } print OUT "$_\n" unless $strip; } } } } close F; close OUT if $DoCommentStripping; $DoCommentStripping = 0; die "no main section is defined for file $file" unless defined($Body{'main'}); $mTitle{$file} = $Title{'main'}; $mAbstract{$file} = $Abstract{'main'}; $toc = "
\n"; for $section ( @section ){ next if $noToc{$section}; $toc .= "
$section "; $toc .= "" . $Title{$section} . "
\n"; if( defined($Abstract{$section}) ){ $toc .= '
' . &htmlizee($Abstract{$section}) . "\n"; } $toc .= "

\n"; } $toc .= "

\n"; push @section,'main'; for $section ( @section ){ mkdir "$DocRoot/$dir",0777 unless -e "$DocRoot/$dir"; if( $section eq 'main' ){ $fn = $MainName; }else{ $fn = $section; } die "can not write $DocRoot/$fn.$HtmlExtension" unless open(F,">$DocRoot/$dir/$fn.$HtmlExtension"); print F "\n\n"; print F '',$Title{$section},"\n" if defined($Title{$section}); print F "\n\n\n"; print F "
\n"; print F "FILE ... " unless $fn eq $MainName; print F "TOC\n"; print F &htmlizee($Body{$section}); if( $section eq 'main' && !$TocInserted ){ print F "

\n"; print F $toc; } print F '

'; print F "FILE ... " unless $fn eq $MainName; print F "TOC\n"; print F "

\n"; print F "
\n\n\n"; close F; } } if( $PackageAbstract ){ $toc = "
\n"; for $File ( @File ){ $toc .= "
$File "; $toc .= '" . $mTitle{$File} . "
\n"; if( defined($mAbstract{$File}) ){ $toc .= '
' . &htmlizee($mAbstract{$File}) . "\n"; } $toc .= "

\n"; } $toc .= "

\n"; die "can not write $DocRoot/$MainName.$HtmlExtension" unless open(F,">$DocRoot/$MainName.$HtmlExtension"); print F "\n\n"; print F '',$PackageTitle,"\n" if defined($PackageTitle); print F "\n\n\n"; print F "
\n"; print F &htmlizee($PackageAbstract); if( !$TocInserted ){ print F $toc; } print F "
\n"; print F "
\n\n"; close F; } exit; sub htmlizee { $TocInserted = 0; my $line = shift; $line =~ s/\
';
next;
}
if( $line =~ /^\s*=noverbatim\s*$/ ){
die 'noverbatim W/O verbatim' unless $verbatim;
$verbatim = 0;
$line = '
'; next; } if( !$verbatim ){ $line =~ s/H\<\;([^>]*)\>/

$1<\/b><\/font>

/g; $line =~ s/B\<\;([^>]*)\>/$1<\/B>/g; $line =~ s/I\<\;([^>]*)\>/$1<\/I>/g; $line =~ s/T\<\;([^>]*)\>/$1<\/TT><\/font>/g; $line =~ /R\<\;([^>]*)\>/; my $ref = $1; if( $ref =~ m#/# ){ if( $ref =~ m#/\s*$# ){ $ref =~ s#/\s*$##; $ref .= "/$MainName" } $line =~ s/R\<\;([^>]*)\>/$1<\/A>/g; }else{ $line =~ s/R\<\;([^>]*)\>/$1<\/A>/g; } } if( !$verbatim && $line =~ /^\s*=itemize\s*$/ ){ $line = '

'; next; } if( !$verbatim && $line =~ /^\s*=hrule\s*$/ ){ $line = '
'; next; } if( !$verbatim && $line =~ /^\s*=italic\s*$/ ){ $line = ''; next; } if( !$verbatim && $line =~ /^\s*=noitalic\s*$/ ){ $line = ''; next; } if( !$verbatim && $line =~ /^\s*=bold\s*$/ ){ $line = ''; next; } if( !$verbatim && $line =~ /^\s*=nobold\s*$/ ){ $line = ''; next; } if( !$verbatim && $line =~ /^\s*=center\s*$/ ){ $line = '
'; next; } if( !$verbatim && $line =~ /^\s*=nocenter\s*$/ ){ $line = '
'; next; } if( length($line) == 0 && !$verbatim ){ $line ='

'; next; } if( $line =~ /^\s*=toc\s*$/ && !$verbatim){ $line = $toc; $TocInserted = 1; next; } } $line = join("\n",@line); return $line; } __END__