123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254 |
- eval 'exec perl -Ssw $0 "$@"'
- if 0;
- # Usage $0 manpage
- # Parse my man page formats.
- die "Usage: $0 [ manpage ] \n" unless $#ARGV <= 0;
- $firstSH = 1;
- $inDL = 0;
- warn "Doing $ARGV[0]\n";
- open(STDIN, "$ARGV[0]") if ($#ARGV == 0);
- while (<>) {
- next if (/^\.\\"/);
- if (/^\.TH\s/) {
- # .TH BW_MEM_CP 8 "$Date$" "(c)1994 Larry McVoy" "LMBENCH"
- split;
- print "<TITLE>$_[1]($_[2]) - LMBENCH man page</TITLE>\n";
- print "<H2>$_[1]($_[2]) - LMBENCH man page</H2><HR>\n";
- next;
- }
- if (/^\.SH\s/) {
- s/.SH\s+//;
- s/"//g;
- chop;
- print "</DL>\n" unless $firstSH; $firstSH = 0;
- print "</DL>\n" if $inDL; $inDL = 0;
- print "<DL><DT><H4>$_</H4><DD>\n";
- next;
- }
- next if &fontfont;
- if (/^\.LP\s/ || /^\.PP/) {
- s/..P\s+//;
- chop;
- print "<P>\n";
- next;
- }
- if (/^\.TP/) { # treat as a DT list
- $_ = <>;
- &html;
- chop;
- print "</DL>\n" if ($inDL);
- print "<DL><DT>";
- print unless &fontfont;
- print "<DD><BR>\n";
- $inDL = 1;
- next;
- }
- if (/^\.IP/) { # treat as a DT list
- s/^\.IP\s*//;
- chop;
- s/"//;
- s/".*//;
- &html;
- print "</DL>\n" if ($inDL);
- print "<DL><DT>$_<DD><BR>\n";
- $inDL = 1;
- next;
- }
- if (/^\.sp/) {
- print "<PRE>\n</PRE>\n";
- next;
- }
- next if (/^\.in/ || /^\.ps/); # skip this stuff.
- if (/^\.br/) {
- print "<BR>\n";
- next;
- }
- if (/^\.nf/ || /^\.DS/) { # starting a display
- print "<PRE>\n";
- while (<>) {
- last if /^\.fi/;
- last if /^\.DE/;
- next if /^\./;
- &html;
- print "\t$_"; # XXX - a screwy way of indenting
- }
- print "</PRE>\n";
- next;
- }
- if (/^\.ft C[WB]/) {
- local($pre) = 0;
- print "<CODE>\n";
- while (<>) {
- last if /^\.ft\s*$/;
- if (/^\.nf/) {
- $pre = 1;
- print "<PRE>\n";
- next;
- }
- if ($pre && /^\.fi/) {
- print "</PRE>\n";
- $pre = 0;
- next;
- }
- next if /^\.br/;
- &html;
- print;
- }
- print "</CODE>\n";
- next;
- }
- if (/\\f\(C[WB]/) {
- &html;
- s/\\f\(C[WB]/<CODE>/;
- while (!/\\f/) {
- &html;
- print;
- $_ = <>;
- }
- s/\\fP/<\/CODE>/;
- print;
- next;
- }
- if (/\\fB/) {
- &html;
- s/\\fB/<STRONG>/;
- while (!/\\f/) {
- print;
- $_ = <>;
- &html;
- }
- s/\\fP/<\/STRONG>/;
- print;
- next;
- }
- if (/\\fI/) {
- &html;
- s/\\fB/<EM>/;
- while (!/\\f/) {
- print;
- $_ = <>;
- &html;
- }
- s/\\fP/<\/EM>/;
- print;
- next;
- }
- if (/^\.ti/) { # one line display
- print "<PRE>\n";
- $_ = <>;
- &html;
- print;
- print "</PRE>\n";
- next;
- }
- if (/^\.de\s+/) {
- s/^\.de\s+//;
- warn "$ARGV[0]: Ignoring definition: $_";
- while (<>) {
- last if /^\.\./;
- }
- next;
- }
-
- # Warn about unimplemented troff/man commands
- if (/^\./) {
- chop;
- warn "$ARGV[0] unimp: \"$_\"\n";
- next;
- }
- if (/\\f/) {
- warn "$ARGV[0]: missed font: \"$_\"\n";
- }
- # Catchall for all the weirdball things I do.
- s/^\\\&\.\\\|\.\\\|\./.../;
- s/\\-/-/;
- &html;
- print;
- }
- exit 0;
- sub html
- {
- # HTML things that I've encountered.
- s/"/"/g;
- s/</</g;
- s/>/>/g;
- }
- sub fontfont {
- if (/^\.BI\s/) {
- s/.BI\s+//;
- chop;
- split;
- print "<STRONG>$_[0]</STRONG><EM>$_[1]</EM>\n";
- return 1;
- }
- if (/^\.IB\s/) {
- s/.IB\s+//;
- chop;
- split;
- print "<EM>$_[0]</EM><STRONG>$_[1]</STRONG>\n";
- return 1;
- }
- if (/^\.IR\s/) {
- s/.IR\s+//;
- chop;
- split;
- print "<EM>$_[0]</EM>$_[1]\n";
- return 1;
- }
- if (/^\.BR\s/) {
- s/.BR\s+//;
- chop;
- split;
- print "<STRONG>$_[0]</STRONG>$_[1]\n";
- return 1;
- }
- if (/^\.B\s/) {
- s/.B\s+//;
- chop;
- print "<STRONG>$_</STRONG>\n";
- return 1;
- }
- if (/^\.I\s/) {
- s/.I\s+//;
- chop;
- print "<EM>$_</EM>\n";
- return 1;
- }
- return 0;
- }
|