#!/sw/bin/perl -w
##################################
# By: Ventz Petkov               #
# Date: 7-01-05                  #
# Convert *.html into Kwiki text #
##################################
use strict;
use LWP::Simple;
use HTML::WikiConverter;
our $wc = new HTML::WikiConverter( dialect => 'Kwiki' );

sub main() {
    if (@ARGV != 1) {
        print "\t\tUsage: ./thtml2wiki.pl some_file.html\n";
        print "\t\tEx: ./thmlt2wiki.pl index.html\n";
        print "\t\tResults are stored in kwiki_results.txt\n";
        exit();
    }
    convert($ARGV[0]);
}
##################################################
# Let's start converting 
sub convert() {
    my $path= shift;
    # Sweet, let's start reading the file
    my $file_path = $path; chomp($file_path);
    my $wiki = $wc->html2wiki( file => $file_path );
    record($wiki);
    close(FP);
}

##################################################
# Write results to a file: kwiki_results.txt
sub record() {
    my $wiki = shift;
    open(FP, ">kwiki_results.txt")
        || die("Cannot write to \"kwiki_results.txt\"");
    print FP $wiki;
}

##################################################
# Start the wheel
main();
