| 1 |
#!/usr/local/bin/perl |
| 2 |
|
| 3 |
use strict; |
| 4 |
use warnings; |
| 5 |
|
| 6 |
use Getopt::Long; |
| 7 |
use Pod::2::DocBook; |
| 8 |
use Pod::Usage; |
| 9 |
|
| 10 |
my $doctype = 'section'; |
| 11 |
my $spaces = 2; |
| 12 |
my ($title, $double_quotes, $help, $no_header); |
| 13 |
|
| 14 |
pod2usage unless GetOptions ('doctype=s' => \$doctype, |
| 15 |
'title=s' => \$title, |
| 16 |
'spaces=i' => \$spaces, |
| 17 |
'fix-double-quotes' => \$double_quotes, |
| 18 |
'no-header' => \$no_header, |
| 19 |
'help' => \$help, |
| 20 |
); |
| 21 |
|
| 22 |
pod2usage if $help; |
| 23 |
pod2usage unless grep { $doctype eq $_ } qw(article chapter |
| 24 |
refentry section); |
| 25 |
pod2usage unless $spaces =~ /^\d+$/; |
| 26 |
|
| 27 |
if (@ARGV == 0) { |
| 28 |
$title = '' unless defined $title; |
| 29 |
my $parser = Pod::2::DocBook->new (title => $title, |
| 30 |
doctype => $doctype, |
| 31 |
fix_double_quotes => $double_quotes, |
| 32 |
header => ! $no_header, |
| 33 |
spaces => $spaces); |
| 34 |
$parser->parse_from_filehandle(\*STDIN); |
| 35 |
} |
| 36 |
|
| 37 |
else { |
| 38 |
my ($infile, $outfile) = @ARGV; |
| 39 |
|
| 40 |
($title) = $infile =~ m!([^/]+)\z! unless defined $title; |
| 41 |
my $parser = Pod::2::DocBook->new (title => $title, |
| 42 |
doctype => $doctype, |
| 43 |
fix_double_quotes => $double_quotes, |
| 44 |
header => ! $no_header, |
| 45 |
spaces => $spaces); |
| 46 |
|
| 47 |
if (defined $outfile) { |
| 48 |
$parser->parse_from_file ($infile, $outfile); |
| 49 |
} |
| 50 |
|
| 51 |
else { |
| 52 |
$parser->parse_from_file ($infile); |
| 53 |
} |
| 54 |
} |
| 55 |
|
| 56 |
|
| 57 |
=head1 NAME |
| 58 |
|
| 59 |
pod2docbook - Convert POD data to DocBook SGML |
| 60 |
|
| 61 |
=head1 SYNOPSIS |
| 62 |
|
| 63 |
pod2docbook [B<--help>] |
| 64 |
[B<--doctype>=B<article>|B<chapter>|B<section>|B<refentry>] |
| 65 |
[B<--title>=I<title>] S<[B<--spaces>=I<# spaces per indent level>]> |
| 66 |
[B<--fix-double-quotes>] [B<--no-header>] S<[I<infile> [I<outfile>]]> |
| 67 |
|
| 68 |
=head1 DESCRIPTION |
| 69 |
|
| 70 |
B<pod2docbook> converts files from pod format (see L<perlpod>) to |
| 71 |
DocBook 4.2 SGML (see L<http://www.docbook.org/>). The program itself |
| 72 |
is merely a driver for the Pod::2::DocBook class; if you're interested in |
| 73 |
details of pod-to-SGML translation see L<Pod::2::DocBook>. |
| 74 |
|
| 75 |
=head1 OPTIONS AND ARGUMENTS |
| 76 |
|
| 77 |
=over |
| 78 |
|
| 79 |
=item [B<--help>] |
| 80 |
|
| 81 |
Print usage and exit. |
| 82 |
|
| 83 |
=item [B<--doctype>=B<article>|B<chapter>|B<section>|B<refentry>] |
| 84 |
|
| 85 |
Specifies the document type for the output file; the default is |
| 86 |
B<section>. |
| 87 |
|
| 88 |
=item [B<--title>=I<title>] |
| 89 |
|
| 90 |
Specifies the document title. The default is I<infile>, if it is |
| 91 |
supplied, or empty string otherwise. |
| 92 |
|
| 93 |
=item [B<--spaces>=I<# spaces per indent level>] |
| 94 |
|
| 95 |
Specifies the number of spaces per indent level in the SGML output; |
| 96 |
the default is 2. |
| 97 |
|
| 98 |
=item [B<--fix-double-quotes>] |
| 99 |
|
| 100 |
Replace pairs of double quotes in regular paragraphs with <quote> and |
| 101 |
</quote> (see L<Pod::2::DocBook> for details). |
| 102 |
|
| 103 |
=item [B<--no-header>] |
| 104 |
|
| 105 |
Omit the DOCTYPE line from the output. |
| 106 |
|
| 107 |
=item I<infile> |
| 108 |
|
| 109 |
The name of the file from which to read pod source; if not supplied, |
| 110 |
STDIN is used for input. |
| 111 |
|
| 112 |
=item I<outfile> |
| 113 |
|
| 114 |
The name of the file to which to write SGML; if not supplied, STDOUT |
| 115 |
is used for output. |
| 116 |
|
| 117 |
=back |
| 118 |
|
| 119 |
=head1 SEE ALSO |
| 120 |
|
| 121 |
L<perlpod>, L<Pod::2::DocBook> |
| 122 |
|
| 123 |
=head1 AUTHOR |
| 124 |
|
| 125 |
Nandu Shah <[email protected]> |
| 126 |
|
| 127 |
=head1 COPYRIGHT |
| 128 |
|
| 129 |
Copyright 2004, Nandu Shah <[email protected]> |
| 130 |
|
| 131 |
This program is free software; you may redistribute it and/or modify |
| 132 |
it under the same terms as Perl itself |
| 133 |
|
| 134 |
=cut |