0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# Copyright (C) 2001, 2004, 2007, 2012, 2016 Internet Systems Consortium, Inc. ("ISC")
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# This Source Code Form is subject to the terms of the Mozilla Public
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# License, v. 2.0. If a copy of the MPL was not distributed with this
0c27b3fe77ac1d5094ba3521e8142d9e7973133fMark Andrews# file, You can obtain one at http://mozilla.org/MPL/2.0/.
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson# Do a quick-and-dirty conversion of .mandoc man pages to
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson# DocBook SGML.
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson# Minor hand editing of the output is usually required.
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson# This has only been tested with library function man pages
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson# (section 3); it probably does not work well for program
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN">
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews - Copyright (C) 2000, 2001 Internet Systems Consortium, Inc. ("ISC")
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews - This Source Code Form is subject to the terms of the Mozilla Public
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews - License, v. 2.0. If a copy of the MPL was not distributed with this
704e6c8876907aac0bf7380effca8bca400d4acdMark Andrews - file, You can obtain one at http://mozilla.org/MPL/2.0/.
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<para>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</para>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</$cursection>\n"
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<$tag>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson next if m/^\.\\\"/;
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson if (/^\.Dd (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<date>$1<\/date>\n<\/refentryinfo>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Dt ([^ ]+) ([^ ]+)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Os (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.ds (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Nm (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson $t =~ s/ ,$//;
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<refname>$t<\/refname>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<command>$1<\/command>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Nd (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<refpurpose>$1</refpurpose>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Sh NAME/) { section("refnamediv"); next; }
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Sh SYNOPSIS/) { section("refsynopsisdiv"); next; }
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Sh (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<title>$1</title>\n"; next;
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson # special: spaces can occur in arg
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Fd (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<funcsynopsisinfo>$_<\/funcsynopsisinfo>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson # special: add parenthesis
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<function>$1()<\/function>$3\n";
8b862ad2b77326a01c6a4045c0ce5f4f428a5120Andreas Gustafsson # special: add dash
8b862ad2b77326a01c6a4045c0ce5f4f428a5120Andreas Gustafsson print "<option>-$1<\/option>$3\n";
8b862ad2b77326a01c6a4045c0ce5f4f428a5120Andreas Gustafsson # special: add dash
8b862ad2b77326a01c6a4045c0ce5f4f428a5120Andreas Gustafsson print "<option>-$1<\/option>$3\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Ft (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<funcprototype>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<funcdef>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<paramdef>$t<\/paramdef>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<parameter>$1<\/parameter>$3\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Fo (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<function>$1<\/function></funcdef>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Xr ([^ ]+) ([^ ]+)( ([^ ]+))?$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<citerefentry>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<refentrytitle>$1</refentrytitle><manvolnum>$2</manvolnum>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</citerefentry>$4\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.([A-Z][a-z]) (.*?)( ([^"]+))?$/ && defined($tagmap{$1})) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson $t =~ s/</</g;
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson $t =~ s/>/>/g;
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<$tag>$t<\/$tag>$punct\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Fc$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</funcprototype>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Pp$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Bd /) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<programlisting>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Ed$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</programlisting>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.Bl /) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<variablelist>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson elsif (/^\.El$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</para>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</listitem>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</variablelist>\n";
8b862ad2b77326a01c6a4045c0ce5f4f428a5120Andreas Gustafsson elsif (/^\.It .. (.*)$/) {
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</listitem>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<varlistentry><term><constant>$1</constant></term>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<listitem>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<para>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "</listitem>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<varlistentry><term><errorcode>$1</errorcode></term>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<listitem>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafsson print "<para>\n";
abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68Andreas Gustafssonprint "</refentry>\n";