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