| |
|
|
| sub basename { |
| $slash = rindex($_[0], "/"); |
| $suffix = rindex($_[0], $_[1]); |
| if ($suffix == -1) {$suffix=length($_[0])}; |
| return substr($_[0], $slash+1, $suffix-$slash-1); |
| } |
|
|
| sub dirname { |
| $slash = rindex($_[0], "/"); |
| if ($slash == -1) {return "."}; |
|
|
| return substr($_[0], 0, $slash); |
| } |
|
|
| sub DoHtml { |
|
|
| $preformat = 0; |
| $page = &basename($_[0], ".htm"); |
| $dir = &dirname($_[0]); |
| $sect = chop($dir); |
| if ($sect == "n") { |
| $sect = chop($dir) . $sect; |
| }; |
| $sect = "1"; |
| $dir = &dirname($dir); |
| $infile = $dir . "/" . $page . ".htm"; |
| $outfile = $dir . "/" . $page . "." . $sect; |
| print "\n*** $dir $sect $page *** \n"; |
| open(INP,$infile) || die "Can't open '$infile' for reading: $!"; |
| if (! &GetTitle($page,$sect)) { |
| print "$infile: Did not find a valid <TITLE> line\n"; |
| close(INP); |
| return; |
| } |
| open(OUT,"> $outfile") || die "Can't open '$outfile' for writing: $!"; |
| print "Converting: $infile to $outfile\n"; |
| &PrintHeader($page,$sect,$TITLE[0]); |
|
|
| while (<INP>) { |
| $result = &DoLine($_); |
| if ($result == 2) { |
| close(INP); |
| close(OUT); |
| return; |
| } |
| if (&DoLine($_) == 1) { |
| s#<#<#g; |
| s#>#>#g; |
| print OUT; |
| } |
| } |
| close(INP); |
| close(OUT); |
| return; |
| } |
|
|
| sub GetTitle { |
| while (<INP>) { |
| if (m#<TITLE>.*MAN page for:#i) { |
| s#<TITLE>##i; |
| s#MAN page for:##i; |
| s |
| @TITLE = split; |
| return 1; |
| } |
| if (m#<TITLE>#) { |
| return 1; |
| } |
| } |
| return 0; |
| } |
|
|
| sub PrintHeader { |
| print OUT ".TH $_[0] $_[1] \"\" \"\" \"\" \"$_[2]\"\n"; |
| |
| |
| } |
|
|
| sub DoStrip { |
| if (m#<.*TITLE>#i) { return 1}; |
| if (m/<.*HEADER>/i) { return 1}; |
| if (m/<.*HEAD>/i) { return 1}; |
| if (m/<.*BODY>/i) { return 1}; |
| if (m/<.*HEADER>/i) { return 1}; |
| if (m/<.*BLINK>/i) { return 1}; |
| if (m/^<A HREF="#toc/i) {return 1}; |
| if (s#<A HREF=".*">#\\*L#i) { |
| s |
| } |
| return 0; |
| } |
|
|
| sub DoLine { |
|
|
| if (m |
| s |
| $preformat = 0; |
| return 1; |
| } |
| |
| if (m#^ *<PRE>#i) { |
| s#^ *<PRE>#\\*C\n.DS#i; |
| $preformat = 1; |
| return 1; |
| } |
| s |
| if (m#<A NAME="toc">#) {return 2}; |
| s#<A NAME=".*">##i; |
| s#<\!\-\-#.\\\" #; |
| s#\-\->##; |
| if (m#^<HR.*>$#i) {return 0}; |
| s#<HR>##i; |
| s#<HR .*>##i; |
| if (&DoStrip($_)) {return 0} |
| &DoFont($_); |
| if (! &DoList($_)) {return 0}; |
| if (! &DoSection($_)) {return 0} |
| &DoEscape($_); |
| &DoPara($_); |
| if (! $preformat) { |
| if (m/^$/) {return 0}; |
| s#^[ \t]*##; |
| s#<.*>##g; |
| } |
| return 1; |
| } |
|
|
| sub DoEscape { |
| s |
| s |
| } |
|
|
| sub DoSection { |
| if (m#^ *Table of Contents *$#) {return 0}; |
| if (m#^<A NAME=".*">$#i) {return 0;} |
| s |
| s |
| s |
| if (m |
| s |
| s |
| s |
| return 1; |
| } |
|
|
|
|
| |
| |
| |
| sub DoPara { |
| s/^<P>/.PP\n/; |
| s/<P>/\n.PP\n/g; |
| return; |
| } |
|
|
| |
| |
| |
| |
| sub DoList { |
| if (m |
| if (m#<DT> *$#i) {chop}; |
| s#^ *<DT>#.LI \"#i; |
| s#<DT>#\n.LI \"#i; |
| s |
|
|
| if (m#^ *<DD> *$#i) {return 0}; |
| if (m |
| if (m |
| s |
| s |
|
|
| s |
| s |
|
|
| s |
| s |
|
|
| s |
| s |
|
|
| s |
| s |
|
|
| s |
| s |
|
|
| s |
| s |
|
|
| s |
| s |
| s |
| s |
|
|
| return 1; |
| } |
|
|
| |
| |
| |
| |
| |
| |
| |
| sub DoFont { |
| s |
| s |
| s |
| s |
|
|
| s |
| s |
| s |
| s |
| s/^ *<P>/<P>/; |
| s/^<P>$/.PP/; |
| s/<P>/.PP\n/g; |
| s/<P>/.PP\n/g; |
| return; |
| } |
|
|
| |
| |
| for $arg (@ARGV) { |
| $isTitle=0; |
| &DoHtml($arg); |
| } |
|
|
| exit |
|
|