#!/usr/bin/perl # TODO: We need to make this more resilient # currently expects args without enforcing $FIL = $NAM = $SEC = @ARGV[0]; $NAM =~ s/^([^.]+)\..+$/$1/; $SEC =~ s/^.+\.([^.]+)$/$1/; $command = "groff"; @args = split(" ", "-Tascii -mdoc $FIL"); $enable_include_links = 0; man($NAM, $SEC); sub man { local($name, $section) = @_; local($_, $title, $head, *MAN); local($html_name, $html_section, $prefix); local(@manargs); local($query) = $name; # $section =~ s/^([0-9ln]).*$/$1/; $section =~ tr/A-Z/a-z/; $prefix = "Man "; if ($alttitle) { $prefix = ""; $title = &encode_title($alttitle); $head = &encode_data($alttitle); } elsif ($section) { $title = &encode_title("${name}($section)"); $head = &encode_data("${name}($section)"); } else { $title = &encode_title("${name}"); $head = &encode_data("${name}"); } print &html_header("$title"); print "
\n"; $html_name = &encode_data($name); $html_section = &encode_data($section); #print Dumper($sectionpath); #print "yy $section yy $manpath\n"; if ($name =~ /^\s*$/) { print "Empty input, no man page given.\n"; return; } if (index($name, '*') != -1) { print "Invalid character input '*': $name\n"; return; } if ($section !~ /^[0-9ln]\w*$/ && $section ne '') { print "Sorry, section `$section' is not valid\n"; return; } if (!$section) { if ($sectionpath->{$manpath}) { $section = "-S " . $sectionpath->{$manpath}{'path'}; } else { $section = ''; } } else { if ($sectionpath->{$manpath}{$section}) { $section = "-S " . $sectionpath->{$manpath}{$section}; } else { $section = "-S $section"; } } # print "X $command{'man'} @manargs -- x $name x\n"; &proc(*MAN, $command, @args) || &mydie ("$0: open of $command{'man'} command failed: $!\n"); if (eof(MAN)) { # print "X $command{'man'} @manargs -- x $name x\n"; print "Sorry, no data found for `$html_name" . ($html_section ? "($html_section)": '') . "'.\n"; return; } local($space) = 1; local(@sect); local($i, $j); while(\n"; print ") { # remove tailing white space if (/^\s+$/) { next if $space; $space = 1; } else { $space = 0; } $_ = &encode_data($_); if($enable_include_links && m,()?\#include()?\s+()?\<\;(.*\.h)\>\;()?,) { $match = $4; ($regexp = $match) =~ s/\./\\\./; s,$regexp,\$match\,; } /^\s/ && # skip headers s,((<[IB]>)?[\w\_\.\-]+\s*([IB]>)?\s*\(([1-9ln][a-zA-Z]*)\)),&mlnk($1),oige; # detect E-Mail Addreses in manpages if (/\@/) { s/([a-z0-9_\-\.]+\@[a-z0-9\-\.]+\.[a-z]+)/$1<\/A>/gi; } # detect URLs in manpages if (m%tp://%) { s,((ftp|http)://[^\s<>\)]+),$1,gi; } if (/^\S+/ && m%^([^<]+)%) { $i = $1; $j = &encode_url($i); s%^([^<]+)%$i%; push(@sect, $1); } print; } close(MAN); print "