#!/usr/bin/perl
#
#Converts txt files into DocBook XML/SGML.
#
$VERSION = '0.4';

use Wt2Db;
$WT2DB = new Wt2Db;

my $txtfile = '';
my $dbfile = '';
my $verbose = 0;
my $error = 0;

# read in cmd-line arguments
#
while (1) {
	if($ARGV[0] eq "-a" or $ARGV[0] eq "--article") {
		$article = 1;
		shift(@ARGV);
	} elsif($ARGV[0] eq "-o" or $ARGV[0] eq "--output-to") {
		shift(@ARGV);
		$dbfile = $ARGV[0];
		shift(@ARGV);
	} 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);
	}

	if ($ARGV[0] eq '') {
		last;
	}
}

$WT2DB->ProcessFile($txtfile, $dbfile, $verbose, $article);

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 XML/SGML.\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 "-a, --article      add DOCTYPE and article tags.\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);
}

