[1885] | 1 | #!/usr/bin/perl -w
|
---|
| 2 |
|
---|
| 3 | ###########################################################################
|
---|
| 4 | #
|
---|
| 5 | # classinfo.pl -- provide information about classifiers
|
---|
| 6 | #
|
---|
| 7 | # A component of the Greenstone digital library software
|
---|
| 8 | # from the New Zealand Digital Library Project at the
|
---|
| 9 | # University of Waikato, New Zealand.
|
---|
| 10 | #
|
---|
| 11 | # Copyright (C) 1999 New Zealand Digital Library Project
|
---|
| 12 | #
|
---|
| 13 | # This program is free software; you can redistribute it and/or modify
|
---|
| 14 | # it under the terms of the GNU General Public License as published by
|
---|
| 15 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 16 | # (at your option) any later version.
|
---|
| 17 | #
|
---|
| 18 | # This program is distributed in the hope that it will be useful,
|
---|
| 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 21 | # GNU General Public License for more details.
|
---|
| 22 | #
|
---|
| 23 | # You should have received a copy of the GNU General Public License
|
---|
| 24 | # along with this program; if not, write to the Free Software
|
---|
| 25 | # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
| 26 | #
|
---|
| 27 | ###########################################################################
|
---|
| 28 |
|
---|
[10230] | 29 | use strict;
|
---|
| 30 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
[1885] | 31 |
|
---|
| 32 | BEGIN {
|
---|
| 33 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
| 34 | die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
|
---|
| 35 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
|
---|
[5882] | 36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
[1885] | 37 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
[14942] | 38 |
|
---|
| 39 | if (defined $ENV{'GSDLEXTS'}) {
|
---|
| 40 | my @extensions = split(/:/,$ENV{'GSDLEXTS'});
|
---|
| 41 | foreach my $e (@extensions) {
|
---|
| 42 | my $ext_prefix = "$ENV{'GSDLHOME'}/ext/$e";
|
---|
| 43 |
|
---|
| 44 | unshift (@INC, "$ext_prefix/perllib");
|
---|
| 45 | unshift (@INC, "$ext_prefix/perllib/cpan");
|
---|
| 46 | }
|
---|
| 47 | }
|
---|
[1885] | 48 | }
|
---|
| 49 |
|
---|
| 50 | use classify;
|
---|
| 51 | use util;
|
---|
[5606] | 52 | use gsprintf;
|
---|
| 53 | use printusage;
|
---|
[1885] | 54 |
|
---|
[10230] | 55 | use parse2;
|
---|
[5606] | 56 |
|
---|
| 57 | my $arguments =
|
---|
[12639] | 58 | [ { 'name' => "collection",
|
---|
| 59 | 'desc' => "{classinfo.collection}",
|
---|
[5606] | 60 | 'type' => "string",
|
---|
[10230] | 61 | 'deft' => "",
|
---|
[5606] | 62 | 'reqd' => "no" },
|
---|
| 63 | { 'name' => "xml",
|
---|
| 64 | 'desc' => "{scripts.xml}",
|
---|
| 65 | 'type' => "flag",
|
---|
| 66 | 'reqd' => "no" },
|
---|
[7952] | 67 | { 'name' => "listall",
|
---|
| 68 | 'desc' => "{scripts.listall}",
|
---|
| 69 | 'type' => "flag",
|
---|
| 70 | 'reqd' => "no" },
|
---|
[11683] | 71 | { 'name' => "describeall",
|
---|
| 72 | 'desc' => "{scripts.describeall}",
|
---|
| 73 | 'type' => "flag",
|
---|
| 74 | 'reqd' => "no" },
|
---|
[5606] | 75 | { 'name' => "language",
|
---|
| 76 | 'desc' => "{scripts.language}",
|
---|
| 77 | 'type' => "string",
|
---|
| 78 | 'reqd' => "no" } ];
|
---|
| 79 |
|
---|
| 80 | my $options = { 'name' => "classinfo.pl",
|
---|
| 81 | 'desc' => "{classinfo.desc}",
|
---|
| 82 | 'args' => $arguments };
|
---|
| 83 |
|
---|
[6921] | 84 | sub gsprintf
|
---|
[5606] | 85 | {
|
---|
[6921] | 86 | return &gsprintf::gsprintf(@_);
|
---|
[1885] | 87 | }
|
---|
| 88 |
|
---|
| 89 | sub main {
|
---|
[12639] | 90 | my $collection = "";
|
---|
[4762] | 91 | my $xml = 0;
|
---|
[7952] | 92 | my $listall = 0;
|
---|
[11683] | 93 | my $describeall = 0;
|
---|
[10230] | 94 | my $language;
|
---|
[1885] | 95 |
|
---|
[10230] | 96 | my $hashParsingResult = {};
|
---|
[12545] | 97 | # general options available to all classifiers
|
---|
[10230] | 98 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
[12545] | 99 | # parse returns -1 if an error occurred
|
---|
| 100 | if($intArgLeftinAfterParsing == -1)
|
---|
[4762] | 101 | {
|
---|
[10230] | 102 | &PrintUsage::print_txt_usage($options, "{classinfo.params}");
|
---|
[4762] | 103 | die "\n";
|
---|
[1885] | 104 | }
|
---|
| 105 |
|
---|
[10230] | 106 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
| 107 | {
|
---|
| 108 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
| 109 | }
|
---|
[6945] | 110 | # If $language has been specified, load the appropriate resource bundle
|
---|
| 111 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
| 112 | if ($language) {
|
---|
| 113 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
| 114 | }
|
---|
[12545] | 115 |
|
---|
| 116 | # If there is not exactly 1 argument left (classifier name), then the arguments were wrong
|
---|
[12613] | 117 | # If the user specified -h, then we output the usage also
|
---|
| 118 | if((@ARGV && $ARGV[0] =~ /^\-+h/) )
|
---|
[12545] | 119 | {
|
---|
| 120 | PrintUsage::print_txt_usage($options, "{classinfo.params}");
|
---|
| 121 | die "\n";
|
---|
| 122 | }
|
---|
[6926] | 123 |
|
---|
[12614] | 124 | # If there is not exactly 1 argument left (classifier name), then the arguments were wrong (apart from if we had listall or describeall set)
|
---|
[12613] | 125 | if ($listall == 0 && $describeall ==0 && $intArgLeftinAfterParsing == 0) {
|
---|
[12614] | 126 | gsprintf(STDERR, "{classinfo.no_classifier_name}\n\n");
|
---|
| 127 | PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
|
---|
[12613] | 128 | die "\n";
|
---|
| 129 | }
|
---|
| 130 |
|
---|
| 131 | # we had some arguments that we weren't expecting
|
---|
| 132 | if ($intArgLeftinAfterParsing > 1) {
|
---|
[12614] | 133 | pop(@ARGV); # assume that the last arg is the classifier name
|
---|
[12613] | 134 | gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
|
---|
[12614] | 135 | PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
|
---|
[12613] | 136 | die "\n";
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[1885] | 139 | # Get classifier
|
---|
| 140 | my $classifier = shift (@ARGV);
|
---|
[10350] | 141 | if (defined $classifier) {
|
---|
| 142 | $classifier =~ s/\.pm$//; # allow xxx.pm as the argument
|
---|
| 143 | }
|
---|
[1885] | 144 |
|
---|
| 145 | # make sure the classifier is loaded from the correct location - a hack.
|
---|
[12639] | 146 | if ($collection ne "") {
|
---|
| 147 | $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
|
---|
[1885] | 148 | } else {
|
---|
[4762] | 149 | $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
|
---|
[1885] | 150 | }
|
---|
[4762] | 151 |
|
---|
[12629] | 152 | if ($listall || $describeall) {
|
---|
[12640] | 153 | my $classify_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "classify");
|
---|
| 154 | my @classifier_list = ();
|
---|
| 155 | if (opendir (INDIR, $classify_dir)) {
|
---|
| 156 | @classifier_list = grep (/\.pm$/, readdir (INDIR));
|
---|
| 157 | closedir (INDIR);
|
---|
[12625] | 158 | }
|
---|
[7952] | 159 |
|
---|
[12640] | 160 | print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
---|
| 161 | print STDERR "<ClassifyList length=\"" . scalar(@classifier_list) . "\">\n";
|
---|
| 162 | foreach my $classifier (@classifier_list) {
|
---|
| 163 | $classifier =~ s/\.pm$//;
|
---|
| 164 | my $classifierobj = &classify::load_classifier_for_info ($classifier);
|
---|
| 165 | if ($describeall) {
|
---|
| 166 | $classifierobj->print_xml_usage(0);
|
---|
[7952] | 167 | }
|
---|
[12640] | 168 | else {
|
---|
| 169 | $classifierobj->print_xml_usage(0, 1);
|
---|
| 170 | }
|
---|
[7952] | 171 | }
|
---|
[12640] | 172 | print STDERR "</ClassifyList>\n";
|
---|
[4762] | 173 | }
|
---|
[11683] | 174 | else {
|
---|
| 175 | &print_single_classifier($classifier, $xml, 1);
|
---|
| 176 | }
|
---|
[1885] | 177 | }
|
---|
| 178 |
|
---|
[12629] | 179 |
|
---|
[11683] | 180 | sub print_single_classifier {
|
---|
| 181 | my ($classifier, $xml, $header) = @_;
|
---|
| 182 | my $classobj = &classify::load_classifier_for_info ($classifier);
|
---|
| 183 | if ($xml) {
|
---|
| 184 | $classobj->print_xml_usage($header);
|
---|
| 185 | }
|
---|
| 186 | else {
|
---|
| 187 | &gsprintf(STDERR, "\n{classinfo.passing_options}\n\n");
|
---|
| 188 | &gsprintf(STDERR, "{classinfo.option_types}:\n\n");
|
---|
| 189 | &gsprintf(STDERR, "{classinfo.specific_options}\n\n");
|
---|
| 190 | &gsprintf(STDERR, "{classinfo.general_options}\n\n");
|
---|
| 191 | &gsprintf(STDERR, "$classifier {classinfo.info}:\n\n");
|
---|
| 192 |
|
---|
| 193 | $classobj->print_txt_usage();
|
---|
| 194 | }
|
---|
| 195 |
|
---|
| 196 | }
|
---|
[1885] | 197 |
|
---|
[11683] | 198 |
|
---|
[5606] | 199 | &main ();
|
---|