#!/usr/bin/perl # xmlmanhtml - simple xml to man converter # Copyright (C) 2000-2002 Oliver Kurth # # 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA use XML::Parser; my $section = ""; my %terminators = ( manpage => "\n", synopsis => "\n", description => "\n", options => "", seealso => "\n", section => "\n", # option => "\n", arg => "", file => "", opt => "", # optdesc => "\n", cmd => "
\n", p => "

" ); sub flush_buf{ local $_; print $buffer; $buffer = ""; } sub handle_start{ local $_; my $expat = shift; my $element = shift; my %attr = @_; flush_buf(); $_ = $element; /^manpage$/ and do{ print "
\n
"; print "

$attr{name}

\n"; print "

" . $attr{desc} . "

\n"; }; /^synopsis$/ and do{ print "

Synopsis

\n"; $section = $element; }; /^description$/ and do{ print "

Description

\n"; $section = $element; }; /^options$/ and do{ print "

Options

\n"; $section = $element; }; /^seealso$/ and do{ print "

see also

\n"; $section = $element; }; /^section$/ and do{ print "

".$attr{name}."

\n"; $section = $attr{name}; }; /^arg$/ and do{ print ""; }; /^file$/ and do{ print ""; }; /^opt$/ and do{ print ""; $opt = 1; }; /^manref$/ and do{ if(!$attr{href}){ print "" . $attr{name} ." (" . $attr{section} . ")"; }else{ print "" . $attr{name}. ""; } }; /^p$/ and do{ print "

"; # $paragraph = 1; # $break = 1; }; /^url$/ and do{ print "".$attr{href}.""; }; } sub handle_end{ local $_; my $expat = shift; my $element = shift; flush_buf(); my %attr = @_; $section = "" if($section eq $element); print $terminators{$element} if($terminators{$element}); } sub handle_char{ local $_; my $expat = shift; my $string = shift; $string =~ s/&/&/gs; $string =~ s//>/gs; $string =~ s/"/"/gs; $buffer .= $string; } MAIN:{ my $file = shift; if (!$file) { print STDERR "You need to specify a file to parse\n"; exit(1); } my $parser = new XML::Parser(Handlers => {Start => \&handle_start, End => \&handle_end, Char => \&handle_char}); print ''; $parser->parsefile($file); print "\n"; }