2002-02-02 04:47:19 +00:00
|
|
|
#!/usr/bin/perl
|
|
|
|
#
|
2002-05-05 21:56:12 +00:00
|
|
|
#Converts txt files into DocBook XML/SGML.
|
2002-02-02 04:47:19 +00:00
|
|
|
#
|
2002-06-25 18:14:58 +00:00
|
|
|
$VERSION = '0.4-CVS';
|
2002-05-01 17:59:52 +00:00
|
|
|
|
2002-04-06 13:13:21 +00:00
|
|
|
use Wt2Db;
|
|
|
|
$WT2DB = new Wt2Db;
|
2002-02-02 04:47:19 +00:00
|
|
|
|
2002-04-06 13:13:21 +00:00
|
|
|
my $txtfile = '';
|
|
|
|
my $dbfile = '';
|
2002-05-27 17:12:31 +00:00
|
|
|
my $doctype = '';
|
2002-06-21 01:50:53 +00:00
|
|
|
my $nonet = 0;
|
|
|
|
my $encoding = 'ISO-8859-1';
|
2002-04-06 13:13:21 +00:00
|
|
|
my $verbose = 0;
|
|
|
|
my $error = 0;
|
2002-02-02 04:47:19 +00:00
|
|
|
|
|
|
|
# read in cmd-line arguments
|
|
|
|
#
|
|
|
|
while (1) {
|
2002-05-27 17:12:31 +00:00
|
|
|
if($ARGV[0] eq "-s" or $ARGV[0] eq "--sgml") {
|
|
|
|
$doctype = 'SGML';
|
|
|
|
shift(@ARGV);
|
|
|
|
} elsif($ARGV[0] eq "-x" or $ARGV[0] eq "--xml") {
|
|
|
|
$doctype = 'XML';
|
2002-05-24 17:58:24 +00:00
|
|
|
shift(@ARGV);
|
2002-06-21 01:50:53 +00:00
|
|
|
} elsif($ARGV[0] eq "-e" or $ARGV[0] eq "--encoding") {
|
|
|
|
shift(@ARGV);
|
|
|
|
$encoding = $ARGV[0];
|
|
|
|
shift(@ARGV);
|
|
|
|
} elsif($ARGV[0] eq "-n" or $ARGV[0] eq "--nonet") {
|
|
|
|
$nonet = 1;
|
|
|
|
shift(@ARGV);
|
2002-05-24 17:58:24 +00:00
|
|
|
} elsif($ARGV[0] eq "-o" or $ARGV[0] eq "--output-to") {
|
2002-02-02 04:47:19 +00:00
|
|
|
shift(@ARGV);
|
|
|
|
$dbfile = $ARGV[0];
|
|
|
|
shift(@ARGV);
|
2002-05-25 22:45:48 +00:00
|
|
|
} elsif($ARGV[0] eq "-V" or $ARGV[0] eq "--verbose") {
|
2002-02-02 04:47:19 +00:00
|
|
|
$verbose++;
|
|
|
|
shift(@ARGV);
|
2002-05-25 22:45:48 +00:00
|
|
|
} elsif($ARGV[0] eq "-v" or $ARGV[0] eq "--version") {
|
2002-05-01 21:21:43 +00:00
|
|
|
&version();
|
|
|
|
exit(0);
|
|
|
|
} elsif($ARGV[0] eq "-h" or $ARGV[0] eq "--help") {
|
|
|
|
&usage();
|
2002-02-02 04:47:19 +00:00
|
|
|
} else {
|
|
|
|
$txtfile = $ARGV[0];
|
|
|
|
shift(@ARGV);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($ARGV[0] eq '') {
|
|
|
|
last;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-06-21 01:50:53 +00:00
|
|
|
$WT2DB->ProcessFile($txtfile, $dbfile, $verbose, $doctype, $nonet, $encoding);
|
2002-05-01 21:21:43 +00:00
|
|
|
|
|
|
|
sub version {
|
|
|
|
print "wt2db version $VERSION\n";
|
|
|
|
print "Copyright (c) 2001, 2002 David Merrill \<david\@lupercalia.net\>.\n";
|
|
|
|
print "\n";
|
2002-05-05 21:56:12 +00:00
|
|
|
print "Converts a WikiText file into DocBook XML/SGML.\n";
|
2002-05-01 21:21:43 +00:00
|
|
|
print "\n";
|
|
|
|
print "This is free software; see the source for copying conditions. There is no\n";
|
2002-06-21 01:50:53 +00:00
|
|
|
print "warranty; not even for merchantability or fitness for a particular purpose.\n\n";
|
2002-05-01 21:21:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
sub usage {
|
|
|
|
my $error = shift;
|
|
|
|
&version;
|
|
|
|
print "Usage: wt2db [OPTIONS] [FILE]\n";
|
|
|
|
print "\n";
|
|
|
|
print "Options:\n";
|
2002-05-27 17:12:31 +00:00
|
|
|
print "-s, --SGML add XML DOCTYPE and article tags.\n";
|
|
|
|
print "-x, --XML add SGML DOCTYPE and article tags.\n";
|
2002-06-21 01:50:53 +00:00
|
|
|
print "-e, --encoding specify character encoding.\n";
|
|
|
|
print "-n, --nonet do not look up documents on the net.\n";
|
2002-05-01 21:21:43 +00:00
|
|
|
print "-o, --output-to write to the specified file.\n";
|
2002-06-21 01:50:53 +00:00
|
|
|
print "-V, --verbose show diagnostic output.\n";
|
|
|
|
print "-v, --version show program version.\n";
|
2002-05-01 21:21:43 +00:00
|
|
|
print "-h, --help show this usage message.\n";
|
|
|
|
exit($error);
|
|
|
|
}
|
|
|
|
|