#! /usr/bin/perl # # man2html.pl Version 1.2 # Copyright 1997, 1998 by Richard Dawe # # This software is distributed under the terms of the GNU General Public # License, which should have been distributed with this file as LICENSE. Please # read the notice below. # # --- # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # # --- # # Description: # # This program uses the 'man' command to generate text output which is then # converted into HTML using the PRE pre-formatted tags. Any references like # "socket(2)" are converted into hyperlinks. # # The program must be run from the directory below the 'man' tree, i.e. the # man pages will be in the relative paths man/man1, man/man2, etc. The pages # will be put into a similar tree with paths like html/html1, etc. # # The program also generates an alphabetic index file in the directory below # the man tree called 'index.html' which has links to all the man pages # converted. # Uses use strict; no strict 'vars'; use FileHandle; use DirHandle; # Copyright message $COPYRIGHT_TEXT = 'man2html.pl Version 1.2, Copyright 1997, 1998 by Richard Dawe'; $COPYRIGHT_MESSAGE = < man2html Translation Issues

man2html Translation Issues

man2html has some problems translating 'man' pages to HTML. These are:


$COPYRIGHT_TEXT EOT $TRANSLATION_LINK = <Please look at the man2html translation issues.
$COPYRIGHT_TEXT EOT # Help message $HELP_MESSAGE = < dirs, e.g. man1 - these two must be consistent for this program # to work properly @MANDIRS = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 'o', 'n', 'l', 'p'); # Recurse into these directories chdir 'man'; for ($i = 0; $i <= $#MANDIRS; $i++) { # Go to next one if this one doesn't exist if (! -e 'man' . $MANDIRS[$i]) { print 'No man pages in section ' . $MANDIRS[$i] . "\n"; next; } #else #{ print 'Converting section ' . $MANDIRS[$i] . "\n"; } # Create html dir if necessary if (! -e '../html/html' . $MANDIRS[$i]) { if (!$OUTPUT_ALLINONE) { mkdir '../html/html' . $MANDIRS[$i], umask; print 'Created \'html/html' . $MANDIRS[$i] . "\' directory\n"; } } # Find all the '.
' files & request them via man & save as HTML in # the HTML directory $man_dh = new DirHandle("man$MANDIRS[$i]"); if (!defined($man_dh)) { die "Unable to open directory man$MANDIRS[$i]: $!"; } @FILES = $man_dh->read(); $man_dh->close(); for ($j = 0; $j <= $#FILES; $j++) { if ( ($FILES[$j] eq '.') || ($FILES[$j] eq '..') ) { next; } $FILES[$j] = lc($FILES[$j]); # Lowercase it for links $FILES[$j] =~ s/$\.$MANDIRS[$i]//; # Remove number extension $MANPAGENAME = $FILES[$j]; #$MANPAGENAME =~ s/$\.$MANDIRS[$i]//; # Done already # Put entry in index push(@INDEXED, ($MANPAGENAME."(".$MANDIRS[$i]."):html".$MANDIRS[$i]."/".$FILES[$j].$HTML_EXTENSION)); } } # Change back to parent directory of 'man' directory chdir('..'); # Sort names of those pages to be converted @INDEXED = sort(@INDEXED); # Create the index file and converted pages in parallel $index_fh = new FileHandle(">html/$INDEX_FILE$HTML_EXTENSION"); if (!defined($index_fh)) { die 'Unable to create index file'; } $index_fh->print( "\n\nMan Page Index\n\n" . "\n

Man Page Index

\n" ); for ($i = 'A'; $i lt 'Z'; $i++) { $index_fh->print("$i "); } $index_fh->print("Z

\n"); $letter = ''; # Used to generate targets for links at top $manhtml = ''; # Converted man page $manhtmlfile = ''; # Converted man page file name $manref = ''; # $manpagename($mansection) style man references $manpagename = ''; # man page name $mansection = ''; # man section for ($i = 0; $i <= $#INDEXED; $i++) { # Get details for the page to be indexed ($manref, $manhtmlfile) = split(/:/, $INDEXED[$i]); ($manpagename, $mansection) = split(/\(/, $manref); chop($mansection); # Do we need a new letter from the alphabet? if (uc(substr($manpagename, 0, 1)) ne $letter) { $letter = uc(substr($manpagename, 0, 1)); $index_fh->print("

$letter

\n"); } # If each man page has an HTML page, generate a link to its file, else # link to later in the page. if (!$OUTPUT_ALLINONE) { $index_fh->print( '$manpagename($mansection)
\n" ); } else { $index_fh->print( '$manpagename($mansection)
\n" ); } } # Divide between table of contents and rest in all-in-one style if ($OUTPUT_ALLINONE) { $index_fh->print("

\n"); } for ($i = 0; $i <= $#INDEXED; $i++) { # Get details for the page to be indexed ($manref, $manhtmlfile) = split(/:/, $INDEXED[$i]); ($manpagename, $mansection) = split(/\(/, $manref); chop($mansection); # --- Generate the HTML for the man page --- # Open the output / use $index_fh if (!$OUTPUT_ALLINONE) { $manhtml_fh = new FileHandle(">html/$manhtmlfile"); } else { $manhtml_fh = $index_fh; } if (!defined($manhtml_fh)) { die "Unable to open output '$manhtmlfile': $!"; } # Convert the man page $manhtml = &man2html($manpagename, $mansection, $HTML_EXTENSION, $OUTPUT_ALLINONE); if (!$OUTPUT_ALLINONE) { $manhtml_fh->print( "\n\n" . "$manpagename($mansection)\n" . "\n" . $manhtml . "
\n

$TRANSLATION_LINK

" . "\n" ); # Done now, so close it $manhtml_fh->close(); } else { $manhtml_fh->print( '

$manpagename($mansection)

\n" . $manhtml ); $manhtml_fh->print( "

" . "[Top]" . "

\n
\n" ); } } # Change the relative link for the translation issues file & output end of # index $TRANSLATION_LINK =~ s/\.\.\/trans$HTML_EXTENSION/trans$HTML_EXTENSION/g; if (!$OUTPUT_ALLINONE) { $index_fh->print("

\n"); } $index_fh->print("\n

$TRANSLATION_LINK

\n\n\n"); $index_fh->close(); # Create the translation issues file &CreateTranslationFile($TRANSLATION_MESSAGE, $HTML_EXTENSION); # Finished exit(0); # ------------ # - man2html - # ------------ # This fetches the required man page and converts it to HTML. The HTML does # not include a header or body tags, so this can be used in the middle of an # HTML document. The HTML is returned as a string. sub man2html { my ($manpagename, $mansection, $htmlext, $localref) = @_; my ($manpage); my ($MANDIRS_REGEXP); # Used in link construction $MANDIRS_REGEXP = '0-9onlp'; # Get the 'raw' output from man warn "Executing: man - $mansection $manpagename"; $manpage = `man - $mansection $manpagename`; # Nuke weird control characters $manpage =~ s/.\x08//g; # Escape characters $manpage =~ s//(gt)/g; # Generate links - if $localref == 1, then links to current document, else # to man pages in html/html/ directory structure. if ($localref == 1) { $manpage =~ s/(\w+)\(([$MANDIRS_REGEXP])\)/\$1($2)\<\/A\>/g; } else { $manpage =~ s/(\w+)\(([$MANDIRS_REGEXP])\)/\$1($2)\<\/A\>/g; } # Return it $manpage = '

' . $manpage . '

'; return($manpage); } sub HTMLFooter { } # ------------------------- # - CreateTranslationFile - # ------------------------- sub CreateTranslationFile { my ($msg, $htmlext) = @_; my ($fh); $fh = new FileHandle(">html/trans$htmlext"); if (! defined($fh)) { die 'Unable to create translation information file'; } $fh->print($msg); $fh->close(); }