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 |
|
---|
29 | use strict;
|
---|
30 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
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");
|
---|
36 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
|
---|
37 | unshift (@INC, "$ENV{'GSDLHOME'}/perllib/classify");
|
---|
38 | }
|
---|
39 |
|
---|
40 | use classify;
|
---|
41 | use util;
|
---|
42 | use gsprintf;
|
---|
43 | use printusage;
|
---|
44 |
|
---|
45 | use parse2;
|
---|
46 |
|
---|
47 | my $arguments =
|
---|
48 | [ { 'name' => "collect",
|
---|
49 | 'desc' => "{classinfo.collect}",
|
---|
50 | 'type' => "string",
|
---|
51 | 'deft' => "",
|
---|
52 | 'reqd' => "no" },
|
---|
53 | { 'name' => "xml",
|
---|
54 | 'desc' => "{scripts.xml}",
|
---|
55 | 'type' => "flag",
|
---|
56 | 'reqd' => "no" },
|
---|
57 | { 'name' => "listall",
|
---|
58 | 'desc' => "{scripts.listall}",
|
---|
59 | 'type' => "flag",
|
---|
60 | 'reqd' => "no" },
|
---|
61 | { 'name' => "language",
|
---|
62 | 'desc' => "{scripts.language}",
|
---|
63 | 'type' => "string",
|
---|
64 | 'reqd' => "no" } ];
|
---|
65 |
|
---|
66 | my $options = { 'name' => "classinfo.pl",
|
---|
67 | 'desc' => "{classinfo.desc}",
|
---|
68 | 'args' => $arguments };
|
---|
69 |
|
---|
70 | sub gsprintf
|
---|
71 | {
|
---|
72 | return &gsprintf::gsprintf(@_);
|
---|
73 | }
|
---|
74 |
|
---|
75 | sub main {
|
---|
76 | my $collect = "";
|
---|
77 | my $xml = 0;
|
---|
78 | my $listall = 0;
|
---|
79 | my $language;
|
---|
80 |
|
---|
81 | my $hashParsingResult = {};
|
---|
82 | my $blnParseFailed = "false";
|
---|
83 | # general options available to all plugins
|
---|
84 | my $intArgLeftinAfterParsing = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
85 | # If there are more than one argument left after parsing, it mean user input too many arguments.
|
---|
86 | # Error occoured will return 0
|
---|
87 | if($intArgLeftinAfterParsing > 1)
|
---|
88 | {
|
---|
89 | &PrintUsage::print_txt_usage($options, "{classinfo.params}");
|
---|
90 | die "\n";
|
---|
91 | }
|
---|
92 |
|
---|
93 | foreach my $strVariable (keys %$hashParsingResult)
|
---|
94 | {
|
---|
95 | eval "\$$strVariable = \$hashParsingResult->{\"\$strVariable\"}";
|
---|
96 | }
|
---|
97 | # If $language has been specified, load the appropriate resource bundle
|
---|
98 | # (Otherwise, the default resource bundle will be loaded automatically)
|
---|
99 | if ($language) {
|
---|
100 | &gsprintf::load_language_specific_resource_bundle($language);
|
---|
101 | }
|
---|
102 |
|
---|
103 | # Get classifier
|
---|
104 | my $classifier = shift (@ARGV);
|
---|
105 | if (defined $classifier) {
|
---|
106 | $classifier =~ s/\.pm$//; # allow xxx.pm as the argument
|
---|
107 | }
|
---|
108 | if (($listall == 0) && (!defined $classifier || $classifier eq "")) {
|
---|
109 | &gsprintf(STDERR, "{classinfo.no_classifier_name}\n\n");
|
---|
110 | &PrintUsage::print_txt_usage($options, "{classinfo.params}", 1);
|
---|
111 | die "\n";
|
---|
112 | }
|
---|
113 |
|
---|
114 | # make sure the classifier is loaded from the correct location - a hack.
|
---|
115 | if ($collect ne "") {
|
---|
116 | $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
|
---|
117 | } else {
|
---|
118 | $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
|
---|
119 | }
|
---|
120 |
|
---|
121 | if ($listall) {
|
---|
122 | my $class_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","classify");
|
---|
123 |
|
---|
124 | if (!opendir (INDIR, $class_dir)) {
|
---|
125 | print STDERR "classinfo.pl: could not open directory $class_dir\n";
|
---|
126 | } else {
|
---|
127 | my @class_list = grep (/\.pm$/, readdir (INDIR));
|
---|
128 | closedir (INDIR);
|
---|
129 |
|
---|
130 | if ($xml) {
|
---|
131 | my $num_class = scalar(@class_list);
|
---|
132 |
|
---|
133 | print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
---|
134 | print STDERR "<!DOCTYPE ClassifyList [\n";
|
---|
135 | print STDERR " <!ELEMENT ClassifyList (ClassifyName*)>\n";
|
---|
136 | print STDERR " <!ELEMENT ClassifyName (#PCDATA)>\n";
|
---|
137 | print STDERR " <!ATTLIST ClassifyList\n";
|
---|
138 | print STDERR " length CDATA #REQUIRED>\n";
|
---|
139 | print STDERR "]>\n";
|
---|
140 |
|
---|
141 | print STDERR "<ClassifyList length=\"$num_class\">\n";
|
---|
142 | map { print STDERR " <ClassifyName>$_</ClassifyName>\n"; } @class_list;
|
---|
143 | print STDERR "</ClassifyList>\n";
|
---|
144 |
|
---|
145 | }
|
---|
146 | else {
|
---|
147 | print STDERR join(" ",@class_list), "\n";
|
---|
148 | }
|
---|
149 | }
|
---|
150 |
|
---|
151 | }
|
---|
152 | else {
|
---|
153 | my $classobj = &classify::load_classifier_for_info ($classifier);
|
---|
154 | if ($xml) {
|
---|
155 | $classobj->print_xml_usage();
|
---|
156 | }
|
---|
157 | else {
|
---|
158 | &gsprintf(STDERR, "\n{classinfo.passing_options}\n\n");
|
---|
159 | &gsprintf(STDERR, "{classinfo.option_types}:\n\n");
|
---|
160 | &gsprintf(STDERR, "{classinfo.specific_options}\n\n");
|
---|
161 | &gsprintf(STDERR, "{classinfo.general_options}\n\n");
|
---|
162 | &gsprintf(STDERR, "$classifier {classinfo.info}:\n\n");
|
---|
163 |
|
---|
164 | $classobj->print_txt_usage();
|
---|
165 | }
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 |
|
---|
170 | &main ();
|
---|