#!/usr/bin/perl -w

###########################################################################
#
# classinfo.pl -- provide information about classifiers
#
# A component of the Greenstone digital library software
# from the New Zealand Digital Library Project at the 
# University of Waikato, New Zealand.
#
# Copyright (C) 1999 New Zealand Digital Library Project
#
# 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., 675 Mass Ave, Cambridge, MA 02139, USA.
#
###########################################################################


BEGIN {
    die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
    die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
    unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
    unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
}

use classify;
use util;
use parsargv;

sub print_usage {
    print STDERR "\n";
    print STDERR "classinfo.pl: Prints information about a classifier.\n\n";
    print STDERR "  usage: $0 [options] classifier\n\n";
    print STDERR "  options:\n";
    print STDERR "   -collect collection-name  Giving a collection name will make\n";
    print STDERR "         classinfo.pl look in collect/collection-name/perllib/classify\n";
    print STDERR "         first. If it doesn't find it there it will look in the general\n";
    print STDERR "         perllib/classify directory.\n\n";
    print STDERR "   -xml                      Produces the information in an xml form, without\n";
    print STDERR "                             'pretty' comments but with much more detail.\n";
}

&main ();

sub main {
    my $collect = "";
    my $xml = 0;

    # Parse command line
    if (!parsargv::parse(\@ARGV, q^collect/.*/^, \$collect, q^xml^, \$xml )) 
    {
	&print_usage();
	die "\n";
    }

    # Get classifier
    my $classifier = shift (@ARGV);
    if (!defined $classifier || $classifier eq "") {
	print STDERR "You must provide a classifier name\n";
	&print_usage();
	die "\n";
    }

    # make sure the classifier is loaded from the correct location - a hack.
    if ($collect ne "") {
	$ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
    } else {
	$ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
    }
 
    my $classinfo = &classify::load_classifiers ([[$classifier]]);
    my $classobj = shift @$classinfo;

    if ($xml) {
        $classobj->print_xml_usage();
    }
    else {
	print STDERR "
$classifier info:

Options may be passed to any classifier by including them in your collect.cfg
configuration file.

Classifiers may take two types of options:

";
	print STDERR "Specific options are defined within the classifier itself, and are available\n";
	print STDERR "only to this particular classifier.\n\n";

	print STDERR "General options are inherited from parent classes of the classifer.\n\n";

	$classobj->print_txt_usage();
    }
}




