#!/usr/bin/perl # # Copyright (C) 2001, 2004, 2007, 2012, 2016 Internet Systems Consortium, Inc. ("ISC") # # This Source Code Form is subject to the terms of the Mozilla Public # License, v. 2.0. If a copy of the MPL was not distributed with this # file, You can obtain one at http://mozilla.org/MPL/2.0/. # $Id$ # # 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";