#!/usr/bin/perl # # Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC") # Copyright (C) 2001 Internet Software Consortium. # # Permission to use, copy, modify, and distribute this software for any # purpose with or without fee is hereby granted, provided that the above # copyright notice and this permission notice appear in all copies. # # THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH # REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY # AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM # LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE # OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR # PERFORMANCE OF THIS SOFTWARE. # $Id: mandoc2docbook.pl,v 1.3.206.1 2004/03/06 13:16:22 marka Exp $ # # Do a quick-and-dirty conversion of .mandoc man pages to # DocBook SGML. # # Minor hand editing of the output is usually required. # This has only been tested with library function man pages # (section 3); it probably does not work well for program # man pages. # print <<\END; END my $cursection = undef; my $in_para = 0; sub begin_para() { if (! $in_para) { print "\n"; $in_para = 1; } } sub end_para() { if ($in_para) { print "\n"; $in_para = 0; } } sub end_section { if ($cursection) { print "\n" } } sub section { my ($tag) = @_; end_para(); end_section(); print "<$tag>\n"; $cursection = $tag; } my %tagmap = ( Er => errorcode, Dv => type, Pa => filename, Li => constant, # XXX guess Ar => parameter, Va => parameter, ); while (<>) { next if m/^\.\\\"/; if (/^\.Dd (.*)$/) { print "$1<\/date>\n<\/refentryinfo>\n"; next; } elsif (/^\.Dt ([^ ]+) ([^ ]+)$/) { my $title = lc $1; my $volume = $2; chomp $volume; print < $title $volume BIND9 END next; } elsif (/^\.Os (.*)$/) { next; } elsif (/^\.ds (.*)$/) { next; } elsif (/^\.Nm (.*)$/) { if ($cursection eq "refnamediv") { my $t = $1; $t =~ s/ ,$//; print "$t<\/refname>\n"; } else { print "$1<\/command>\n"; } next; } elsif (/^\.Nd (.*)$/) { print "$1\n"; next; } elsif (/^\.Sh NAME/) { section("refnamediv"); next; } elsif (/^\.Sh SYNOPSIS/) { section("refsynopsisdiv"); next; } elsif (/^\.Sh (.*)$/) { section("refsect1"); print "$1\n"; next; } # special: spaces can occur in arg elsif (/^\.Fd (.*)$/) { $_ = $1; s//>/g; print "$_<\/funcsynopsisinfo>\n"; next; } elsif (/^\.Fn (.*?)( ([^"]+))?$/) { # special: add parenthesis print "$1()<\/function>$3\n"; } elsif (/^\.Op Fl (.*?)( ([^"]+))?$/) { # special: add dash print "\n";