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
|
|
|
#
|
2003-05-18 13:39:35 +00:00
|
|
|
# Copyright (c) 2001, 2002, 2003 David Merrill <david@lupercalia.net>.
|
2002-06-26 07:29:34 +00:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
2005-01-22 20:46:26 +00:00
|
|
|
$VERSION = '1.0';
|
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 = '';
|
2003-05-19 04:47:32 +00:00
|
|
|
my $doctype = 0;
|
2003-05-18 22:14:08 +00:00
|
|
|
my $articleclass = '';
|
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);
|
2003-05-18 22:14:08 +00:00
|
|
|
} elsif($ARGV[0] eq "-f" or $ARGV[0] eq "--faq") {
|
|
|
|
$articleclass = 'faq';
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-05-18 22:14:08 +00:00
|
|
|
$WT2DB->ProcessFile($txtfile, $dbfile, $verbose, $doctype, $articleclass, $nonet, $encoding);
|
2002-05-01 21:21:43 +00:00
|
|
|
|
|
|
|
sub version {
|
|
|
|
print "wt2db version $VERSION\n";
|
2005-01-22 20:46:26 +00:00
|
|
|
print "Copyright (c) 2001, 2002, 2003, 2004, 2005 David Merrill \<david\@lupercalia.net\>.\n";
|
2002-05-01 21:21:43 +00:00
|
|
|
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";
|
2003-05-18 22:14:08 +00:00
|
|
|
print "-s, --sgml add XML DOCTYPE and article tags.\n";
|
|
|
|
print "-x, --xml add SGML DOCTYPE and article tags.\n";
|
|
|
|
print "-f, --faq make the article a faq.\n";
|
|
|
|
print "-e, --encoding specify character encoding.\n";
|
2002-06-21 01:50:53 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|