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