From abeaa7aeb56fd0c9c60d8fe1cc98a3cc94f4fe68 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Sat, 31 Mar 2001 00:11:20 +0000 Subject: [PATCH] created --- util/mandoc2docbook.pl | 239 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 239 insertions(+) create mode 100644 util/mandoc2docbook.pl diff --git a/util/mandoc2docbook.pl b/util/mandoc2docbook.pl new file mode 100644 index 0000000000..98f319ff30 --- /dev/null +++ b/util/mandoc2docbook.pl @@ -0,0 +1,239 @@ +#!/usr/bin/perl +# +# Copyright (C) 2001 Nominum Inc +# +# 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 INTERNET SOFTWARE CONSORTIUM +# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL +# INTERNET SOFTWARE CONSORTIUM 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.1 2001/03/31 00:11:20 gson 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 +); + +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 (/^\.Ft (.*)$/) { + print "\n"; + print "\n"; + print "$1\n"; + next; + } + elsif (/^\.Fa (.*?)( ([^"]+))?$/) { + if ($cursection eq "refsynopsisdiv") { + my $t = $1; + $t =~ s/^"//; + $t =~ s/"$//; + print "$t<\/paramdef>\n"; + } else { + print "$1<\/parameter>$3\n"; + } + next; + } + elsif (/^\.Fo (.*)$/) { + print "$1<\/function>\n"; + next; + } + elsif (/^\.Xr ([^ ]+) ([^ ]+)( ([^ ]+))?$/) { + print "\n"; + print "$1$2\n"; + print "$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//>/g; + print "<$tag>$t<\/$tag>$punct\n"; + next; + } + elsif (/^\.Fc$/) { + print "\n"; + next; + } + elsif (/^\.Pp$/) { + end_para(); + begin_para(); + } + elsif (/^\.Bd /) { + print "\n"; + } + elsif (/^\.Ed$/) { + print "\n"; + } + elsif (/^\.Bl /) { + print "\n"; + } + elsif (/^\.El$/) { + print "\n"; + print "\n"; + print "\n"; + $in_list = 0; + } + elsif (/^\.It Li (.*)$/) { + if ($in_list) { + print "\n"; + } + print "$1\n"; + print "\n"; + print "\n"; + $in_list = 1; + } + elsif (/^\.It Dv (.*)$/) { + if ($in_list) { + print "\n"; + } + print "$1\n"; + print "\n"; + print "\n"; + $in_list = 1; + } else { + if (/./) { + begin_para(); + } + print; + } +} + +end_para(); +end_section(); +print "\n";