#!/usr/bin/perl -w
#
# htmlizer.pl
# Joel Uckelman
# 6 February 2001
#
my $start_prog = time;

require 5.005;
use DBI;

# Configuration
my ($prog, $ver) = ('htmlizer.pl', '0.2');
my ($scripts_config, $prog_config, $subs) = ('/home/g1/bin/scripts.conf', '/home/g1/bin/htmlizer.conf', '/home/g1/bin/htmlizerlib.pl');

print "$prog version $ver\n";

# Assign to some variables in the config to avoid a warning about using them only once.
$database = $password = $port = $host = $user = '';

# looks nice
my $config_start = time;
print 'configuring: ';

# Load the subs and config files
eval { require $scripts_config; };
die "\n$prog: $scripts_config: $@" if $@;
eval { require $subs; };
die "\n$prog: $prog_config: $@" if $@;
eval { require $prog_config; };
die "\n$prog: $prog_config: $@" if $@;

# Are there targets?
defined $ARGV[0] or die "\n$prog: no target";

# Connect to game database
$db = DBI->connect("DBI:mysql:database=$database;host=$host;port=$port", $user, $password) or die "\n$prog: database connect failed: $DBI::errstr";

# Flush after each print (for progress dots)
$| = 1;

# Finish remaining configuration
print 'done, ', time-$config_start, "s\033[60G[ ok ]\n";

# Iterate over target list
my $target;
while ($target = shift @ARGV) {
	print "making $target: ";

	die "\n$prog: undefined target '$target'" unless grep /$target/, (@all, 'all');

	if ($target eq 'all') { unshift @ARGV, @all; } 
	else {
		die "\n$prog: undefined target function '$target'" unless defined(&$target);
		print "done\033[60G[ @{[&$target]} ]";
	}	
	print "\n";
}

$db->disconnect or die "\n$prog: database disconnect failed: $DBI::errstr"; # Wierd! Should never happen.
print 'done, ', time-$start_prog, "s\n";
