mirror of https://github.com/tLDP/LDP
parent
aa7a1c1ddf
commit
200ff1574b
|
@ -3,24 +3,26 @@
|
|||
## Makefile for the wt2db Perl module.
|
||||
##
|
||||
## Copyright (c) 2001, 2002, David Merrill. All rights reserved.
|
||||
## This code is free software; you can redistribute it and/or modify
|
||||
## it under the same terms as Perl itself.
|
||||
## This code is Free Software; you can redistribute it and/or modify
|
||||
## it under the GNU General Public License. See COPYING for details.
|
||||
##
|
||||
|
||||
use ExtUtils::MakeMaker;
|
||||
|
||||
WriteMakefile(
|
||||
|
||||
NAME => 'Wt2Db',
|
||||
AUTHOR => 'David Merrill <david@lupercalia.net>',
|
||||
ABSTRACT => 'Converts WikiText documents into DocBook XML.',
|
||||
NOECHO => '',
|
||||
VERSION_FROM => 'lib/Wt2Db.pm',
|
||||
EXE_FILES => 'wt2db',
|
||||
PREREQ_PM => {
|
||||
'File::Basename' => 0,
|
||||
'HTML::Entities' => 0,
|
||||
'FileHandle' => 0,
|
||||
},
|
||||
|
||||
NAME => 'Wt2Db',
|
||||
AUTHOR => 'David Merrill <david@lupercalia.net>',
|
||||
ABSTRACT => 'Converts WikiText documents into DocBook XML.',
|
||||
NOECHO => '',
|
||||
VERSION_FROM => 'lib/Wt2Db.pm',
|
||||
EXE_FILES => [ qw( wt2db ) ],
|
||||
PREREQ_PM => {
|
||||
'File::Basename' => 0,
|
||||
'HTML::Entities' => 0,
|
||||
'FileHandle' => 0,
|
||||
},
|
||||
MAN1PODS => {
|
||||
"doc/wt2db.pod" => 'blib/man1/wt2db.1',
|
||||
},
|
||||
);
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
=head1 NAME
|
||||
|
||||
B<wt2db> - utility to convert WikiText documents into DocBook XML.
|
||||
|
||||
=head1 SYNOPSIS
|
||||
|
||||
B<wt2db> [I<OPTION>] [I<FILE>]
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
B<wt2db> converts a text file in a special format similar to that used
|
||||
in WikiWikiWebs into valid DocBook XML.
|
||||
|
||||
By default it reads from STDIN and writes to STDOUT. However, if given a
|
||||
filename, it will read that file, and an output filename can also be
|
||||
specified.
|
||||
|
||||
=head1 OPTIONS
|
||||
|
||||
B<-o>, B<--output-to> I<filename> write to the specified file.
|
||||
|
||||
B<-v>, B<--verbose> show diagnostic output.
|
||||
|
||||
B<-h>, B<--help> show a usage message.
|
||||
|
||||
=head1 BUGS
|
||||
|
||||
None currently known. Please report bugs to the author at
|
||||
<david@lupercalia.net>.
|
||||
|
||||
=head1 RESTRICTIONS
|
||||
|
||||
Currently only a single form of WikiText is supported, which is very
|
||||
similar to that used by the Wikipedia (see http://www.wikipedia.com).
|
||||
A future release will be configurable to support additional styles of
|
||||
WikiText.
|
||||
|
||||
=head1 NOTES
|
||||
|
||||
B<wt2db> was developed as a project of the Linux Documentation Project
|
||||
to create an easier way of writing DocBook documentation. While it is
|
||||
useful on its own, it is part of Lampadas, the LDP's document
|
||||
production system.
|
||||
|
||||
=head1 SEE ALSO
|
||||
|
||||
See the home page of the Linux Documentation Project,
|
||||
http://www.tldp.org for updates and more information.
|
||||
|
||||
=head1 AUTHOR
|
||||
|
||||
This man page was written by David C. Merrill <david@lupercalia.net>.
|
||||
|
||||
Permission is granted to copy, distribute and/or modify this document under
|
||||
the terms of the GNU Free Documentation License, Version 1.1 or any later
|
||||
version published by the Free Software Foundation; with no Invariant Sections,
|
||||
no Front-Cover Texts and no Back-Cover Texts.
|
||||
|
||||
=cut
|
||||
|
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
package Wt2Db;
|
||||
|
||||
$VERSION = '0.2';
|
||||
$VERSION = '0.3';
|
||||
|
||||
use File::Basename;
|
||||
use HTML::Entities;
|
||||
|
@ -19,7 +19,6 @@ use Exporter;
|
|||
ProcessEnd,
|
||||
Buffer,
|
||||
Reset,
|
||||
Usage
|
||||
);
|
||||
|
||||
# These keep track of which constructs we're in the middle of
|
||||
|
@ -71,8 +70,8 @@ sub ProcessFile {
|
|||
#
|
||||
if ($txtfile) {
|
||||
if( !(-r $txtfile) ) {
|
||||
print "txt2db: ERROR cannot read $f ($!)\n\n";
|
||||
&usage(1);
|
||||
print "wt2db: ERROR cannot read $f ($!)\n\n";
|
||||
exit(1);
|
||||
} else {
|
||||
$fh = new FileHandle;
|
||||
open $fh, "<$txtfile" or die "Cannot open $txtfile ($!)\n";
|
||||
|
@ -174,10 +173,10 @@ sub ProcessLine {
|
|||
} elsif ($link =~ /^ldp:/) {
|
||||
$linkname =~ s/^ldp://;
|
||||
$link =~ s/^ldp://;
|
||||
$tempfile = "/tmp/txt2db-" . $rand;
|
||||
$tempfile = "/tmp/wt2db-" . $rand;
|
||||
$cmd = "wget -q http://db.linuxdoc.org/cgi-pub/ldp-xml.pl?name=$link -O $tempfile";
|
||||
system("$cmd");
|
||||
open(URL, "$tempfile") || die "txt2db: cannot open temporary file ($!)\n\n";
|
||||
open(URL, "$tempfile") || die "wt2db: cannot open temporary file ($!)\n\n";
|
||||
$link = "";
|
||||
while ($url_line = <URL>) {
|
||||
$url_line =~ s/\n//;
|
||||
|
@ -559,15 +558,4 @@ sub splittitle {
|
|||
$id =~ s/\s+$//;
|
||||
$id =~ s/^\s+//;
|
||||
}
|
||||
|
||||
sub Usage {
|
||||
my $error = shift;
|
||||
print "Usage: wt2db [OPTIONS] {FILE]\n";
|
||||
print "\n";
|
||||
print "Options:\n";
|
||||
print "-o, --output-to write to the specified file.\n";
|
||||
print "-v, --verbose show diagnostic output.\n";
|
||||
print "-h, --help show this usage message.\n";
|
||||
exit($error);
|
||||
}
|
||||
1;
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#
|
||||
#Converts txt files into docbook.
|
||||
#
|
||||
$VERION = '0.2';
|
||||
$VERSION = '0.3';
|
||||
|
||||
use Wt2Db;
|
||||
$WT2DB = new Wt2Db;
|
||||
|
@ -19,11 +19,14 @@ while (1) {
|
|||
shift(@ARGV);
|
||||
$dbfile = $ARGV[0];
|
||||
shift(@ARGV);
|
||||
} elsif($ARGV[0] eq "-h" or $ARGV[0] eq "--help") {
|
||||
$WT2DB->Usage();
|
||||
} elsif($ARGV[0] eq "-v" or $ARGV[0] eq "--verbose") {
|
||||
$verbose++;
|
||||
shift(@ARGV);
|
||||
} elsif($ARGV[0] eq "-V" or $ARGV[0] eq "--version") {
|
||||
&version();
|
||||
exit(0);
|
||||
} elsif($ARGV[0] eq "-h" or $ARGV[0] eq "--help") {
|
||||
&usage();
|
||||
} else {
|
||||
$txtfile = $ARGV[0];
|
||||
shift(@ARGV);
|
||||
|
@ -35,3 +38,27 @@ while (1) {
|
|||
}
|
||||
|
||||
$WT2DB->ProcessFile($txtfile, $dbfile, $verbose);
|
||||
|
||||
sub version {
|
||||
print "wt2db version $VERSION\n";
|
||||
print "Copyright (c) 2001, 2002 David Merrill \<david\@lupercalia.net\>.\n";
|
||||
print "\n";
|
||||
print "Converts a WikiText file into DocBook.\n";
|
||||
print "\n";
|
||||
print "This is free software; see the source for copying conditions. There is no\n";
|
||||
print "warranty; not even for merchantability or fitness for a particular purpose.\n";
|
||||
}
|
||||
|
||||
sub usage {
|
||||
my $error = shift;
|
||||
&version;
|
||||
print "Usage: wt2db [OPTIONS] [FILE]\n";
|
||||
print "\n";
|
||||
print "Options:\n";
|
||||
print "-o, --output-to write to the specified file.\n";
|
||||
print "-v, --verbose show diagnostic output.\n";
|
||||
print "-V, --version show program version.\n";
|
||||
print "-h, --help show this usage message.\n";
|
||||
exit($error);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue