mandoc2docbook.pl revision dafcb997e390efa4423883dafd100c975c4095d6
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff#!/usr/bin/perl
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
40f53fa8d9c6a4fc38c0014495e7a42b08f52481David Lawrence# Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2001 Internet Software Consortium.
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews#
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Permission to use, copy, modify, and distribute this software for any
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff# purpose with or without fee is hereby granted, provided that the above
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff# copyright notice and this permission notice appear in all copies.
70e5a7403f0e0a3bd292b8287c5fed5772c15270Automatic Updater#
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein# REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9c3531d72aeaad6c5f01efe6a1c82023e1379e4dDavid Lawrence# AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
9416e9751e522256dd6dd60d56cb4e8e8f549149Andreas Gustafsson# INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
9416e9751e522256dd6dd60d56cb4e8e8f549149Andreas Gustafsson# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
e7fb847ed570dd8c1bcdacabb3d69bd81feb79aeMark Andrews# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff# PERFORMANCE OF THIS SOFTWARE.
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff# $Id: mandoc2docbook.pl,v 1.4 2004/03/05 05:14:16 marka Exp $
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
364a82f7c25b62967678027043425201a5e5171aBob Halley#
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff# Do a quick-and-dirty conversion of .mandoc man pages to
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff# DocBook SGML.
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff#
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff# Minor hand editing of the output is usually required.
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff# This has only been tested with library function man pages
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff# (section 3); it probably does not work well for program
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff# man pages.
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff#
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graffprint <<\END;
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff<!--
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff - Copyright (C) 2000, 2001 Internet Software Consortium.
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff -
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff - Permission to use, copy, modify, and distribute this software for any
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - purpose with or without fee is hereby granted, provided that the above
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - copyright notice and this permission notice appear in all copies.
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff -
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - INTERNET SOFTWARE CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff - INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff - FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21cbbc3e8301f3959fa1c37d1ee7d597e15c5bf3Michael Graff - NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
ab023a65562e62b85a824509d829b6fad87e00b1Rob Austein - WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff-->
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<!-- $Id: mandoc2docbook.pl,v 1.4 2004/03/05 05:14:16 marka Exp $ -->
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<refentry>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<refentryinfo>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael GraffEND
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graffmy $cursection = undef;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graffmy $in_para = 0;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graffsub begin_para() {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff if (! $in_para) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff print "<para>\n";
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff $in_para = 1;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff}
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graffsub end_para() {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff if ($in_para) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff print "</para>\n";
767fd19da4b699aae46959d834f53af0e1166e80Mark Andrews $in_para = 0;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff}
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graffsub end_section {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff if ($cursection) {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print "</$cursection>\n"
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff}
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graffsub section {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff my ($tag) = @_;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff end_para();
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff end_section();
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff print "<$tag>\n";
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff $cursection = $tag;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff}
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graffmy %tagmap = (
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff Er => errorcode,
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff Dv => type,
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff Pa => filename,
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff Li => constant, # XXX guess
f1b68725503ff3e46001eee5a1751e29a43a09d1Andreas Gustafsson Ar => parameter,
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff Va => parameter,
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff);
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graffwhile (<>) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff next if m/^\.\\\"/;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff if (/^\.Dd (.*)$/) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff print "<date>$1<\/date>\n<\/refentryinfo>\n";
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff next;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff elsif (/^\.Dt ([^ ]+) ([^ ]+)$/) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff my $title = lc $1;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff my $volume = $2;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff chomp $volume;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print <<END;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<refmeta>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<refentrytitle>$title</refentrytitle>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<manvolnum>$volume</manvolnum>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff<refmiscinfo>BIND9</refmiscinfo>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff</refmeta>
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael GraffEND
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff next;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff elsif (/^\.Os (.*)$/) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff next;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.ds (.*)$/) {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff next;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.Nm (.*)$/) {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff if ($cursection eq "refnamediv") {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff my $t = $1;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff $t =~ s/ ,$//;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print "<refname>$t<\/refname>\n";
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff } else {
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff print "<command>$1<\/command>\n";
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff next;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.Nd (.*)$/) {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print "<refpurpose>$1</refpurpose>\n";
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff next;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.Sh NAME/) { section("refnamediv"); next; }
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff elsif (/^\.Sh SYNOPSIS/) { section("refsynopsisdiv"); next; }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.Sh (.*)$/) {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff section("refsect1");
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print "<title>$1</title>\n"; next;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff # special: spaces can occur in arg
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.Fd (.*)$/) {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff $_ = $1;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff s/</&lt;/g;
b8ef99c3a7be2835b2395faff2d46e46f5c4adb3Michael Graff s/>/&gt;/g;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print "<funcsynopsisinfo>$_<\/funcsynopsisinfo>\n";
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff next;
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff }
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff elsif (/^\.Fn (.*?)( ([^"]+))?$/) {
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff # special: add parenthesis
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff print "<function>$1()<\/function>$3\n";
ad91a3d204891c4b039606f9b5ef557d9036f8c8Michael Graff }
elsif (/^\.Op Fl (.*?)( ([^"]+))?$/) {
# special: add dash
print "<option>-$1<\/option>$3\n";
}
elsif (/^\.Fl (.*?)( ([^"]+))?$/) {
# special: add dash
print "<option>-$1<\/option>$3\n";
}
elsif (/^\.Ft (.*)$/) {
print "<funcprototype>\n";
print "<funcdef>\n";
print "$1\n";
next;
}
elsif (/^\.Fa (.*?)( ([^"]+))?$/) {
if ($cursection eq "refsynopsisdiv") {
my $t = $1;
$t =~ s/^"//;
$t =~ s/"$//;
print "<paramdef>$t<\/paramdef>\n";
} else {
print "<parameter>$1<\/parameter>$3\n";
}
next;
}
elsif (/^\.Fo (.*)$/) {
print "<function>$1<\/function></funcdef>\n";
next;
}
elsif (/^\.Xr ([^ ]+) ([^ ]+)( ([^ ]+))?$/) {
print "<citerefentry>\n";
print "<refentrytitle>$1</refentrytitle><manvolnum>$2</manvolnum>\n";
print "</citerefentry>$4\n";
next;
}
elsif (/^\.([A-Z][a-z]) (.*?)( ([^"]+))?$/ && defined($tagmap{$1})) {
my $tag = $tagmap{$1};
my $t = $2;
my $punct = $4;
$t =~ s/^"//;
$t =~ s/"$//;
$t =~ s/</&lt;/g;
$t =~ s/>/&gt;/g;
print "<$tag>$t<\/$tag>$punct\n";
next;
}
elsif (/^\.Fc$/) {
print "</funcprototype>\n";
next;
}
elsif (/^\.Pp$/) {
end_para();
begin_para();
}
elsif (/^\.Bd /) {
print "<programlisting>\n";
}
elsif (/^\.Ed$/) {
print "</programlisting>\n";
}
elsif (/^\.Bl /) {
print "<variablelist>\n";
}
elsif (/^\.El$/) {
print "</para>\n";
print "</listitem>\n";
print "</variablelist>\n";
$in_list = 0;
}
elsif (/^\.It .. (.*)$/) {
if ($in_list) {
print "</listitem>\n";
}
print "<varlistentry><term><constant>$1</constant></term>\n";
print "<listitem>\n";
print "<para>\n";
$in_list = 1;
}
elsif (/^\.It Dv (.*)$/) {
if ($in_list) {
print "</listitem>\n";
}
print "<varlistentry><term><errorcode>$1</errorcode></term>\n";
print "<listitem>\n";
print "<para>\n";
$in_list = 1;
} else {
if (/./) {
begin_para();
}
print;
}
}
end_para();
end_section();
print "</refentry>\n";