source: main/trunk/greenstone2/bin/script/plugoutinfo.pl@ 26441

Last change on this file since 26441 was 17201, checked in by kjdon, 16 years ago

fixed a bug in printing txt usage

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.4 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# plugoutinfo.pl --
6# A component of the Greenstone digital library software
7# from the New Zealand Digital Library Project at the
8# University of Waikato, New Zealand.
9#
10# Copyright (C) 1999 New Zealand Digital Library Project
11#
12# This program is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# This program is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with this program; if not, write to the Free Software
24# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25#
26###########################################################################
27
28# This program will print info about a plugout
29
30use strict;
31no strict 'subs'; # allow barewords (eg STDERR) as function arguments
32
33BEGIN {
34 die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
35 die "GSDLOS not set\n" unless defined $ENV{'GSDLOS'};
36 unshift (@INC, "$ENV{'GSDLHOME'}/perllib");
37 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/cpan");
38 unshift (@INC, "$ENV{'GSDLHOME'}/perllib/plugouts");
39}
40
41use plugout;
42use util;
43use gsprintf;
44use printusage;
45use parse2;
46
47my $arguments =
48 [ { 'name' => "collection",
49 'desc' => "{plugoutinfo.collection}",
50 'type' => "string",
51 'reqd' => "no" },
52 { 'name' => "xml",
53 'desc' => "{scripts.xml}",
54 'type' => "flag",
55 'reqd' => "no" },
56 { 'name' => "listall",
57 'desc' => "{scripts.listall}",
58 'type' => "flag",
59 'reqd' => "no" },
60 { 'name' => "describeall",
61 'desc' => "{scripts.describeall}",
62 'type' => "flag",
63 'reqd' => "no" },
64 { 'name' => "language",
65 'desc' => "{scripts.language}",
66 'type' => "string",
67 'reqd' => "no" } ];
68
69my $options = { 'name' => "plugoutinfo.pl",
70 'desc' => "{plugoutinfo.desc}",
71 'args' => $arguments };
72
73sub gsprintf
74{
75 return &gsprintf::gsprintf(@_);
76}
77
78
79sub main {
80 my $collection = "";
81 my $xml = 0;
82 my $listall = 0;
83 my $describeall = 0;
84 my ($language, $encoding);
85
86 my $hashParsingResult = {};
87 # general options available to all plugouts
88 my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
89
90 # parse returns -1 if an error occurred
91 if ($unparsed_args == -1) {
92
93 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
94 die "\n";
95 }
96
97 foreach my $strVariable (keys %$hashParsingResult)
98 {
99 my $value = $hashParsingResult->{$strVariable};
100 # test to make sure the variable name is 'safe'
101 if ($strVariable !~ /^\w+$/) {
102 die "variable name '$strVariable' isn't safe!";
103 }
104 eval "\$$strVariable = \$value";
105
106 }
107
108 # if language wasn't specified, see if it is set in the environment
109 # (LC_ALL or LANG)
110 if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
111 m/^([^\.]+)\.?(.*)/;
112 $language=$1;
113 $encoding=$2; # might be undef...
114# gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
115 $language =~ s/_.*$//;
116 }
117
118 # If $language has been set, load the appropriate resource bundle
119 # (Otherwise, the default resource bundle will be loaded automatically)
120 if ($language) {
121 gsprintf::load_language_specific_resource_bundle($language);
122 if ($encoding) {
123 $encoding =~ tr/-/_/;
124 $encoding = lc($encoding);
125 $encoding =~ s/utf_8/utf8/; # special
126 $gsprintf::specialoutputencoding=$encoding;
127 }
128 }
129
130 # If there is not exactly 1 argument left (plugout name), then the arguments were wrong
131 # Or if the user specified -h, then we output the usage also
132 if(@ARGV && $ARGV[0] =~ /^\-+h/ )
133 {
134 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
135 die "\n";
136 }
137
138 # If there is not exactly 1 argument left (plugout name), then the arguments were wrong (apart from if we had listall or describeall set)
139 if ($listall == 0 && $describeall ==0 && $unparsed_args == 0) {
140 gsprintf(STDERR, "{plugoutinfo.no_plugout_name}\n\n");
141 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}", 1);
142 die "\n";
143 }
144
145 # we had some arguments that we weren't expecting
146 if ($unparsed_args > 1) {
147 pop(@ARGV); # assume that the last arg is the plugout name
148 gsprintf(STDERR, "{common.invalid_options}\n\n", join (',', @ARGV));
149 PrintUsage::print_txt_usage($options, "{plugoutinfo.params}", 1);
150 die "\n";
151 }
152
153 my $plugout_name = shift (@ARGV);
154
155 if (defined $plugout_name) {
156 $plugout_name =~ s/\.pm$//; # allow xxxPlugout.pm as the argument
157 }
158
159 if ($collection ne "") {
160 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
161 } else {
162 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
163 }
164
165 if ($listall || $describeall) {
166 my $plugouts_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'}, "perllib", "plugouts");
167 my @plugout_list = ();
168 if (opendir (INDIR, $plugouts_dir)) {
169 @plugout_list = grep (/Plugout\.pm$/, readdir (INDIR));
170 closedir (INDIR);
171 }
172
173 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
174 print STDERR "<PlugoutList length=\"" . scalar(@plugout_list) . "\">\n";
175 foreach my $plugout_name (@plugout_list) {
176 $plugout_name =~ s/\.pm$//;
177 my $plugout;
178 push @$plugout,$plugout_name;
179 my $plugoutobj = &plugout::load_plugout ($plugout);
180 if ($describeall) {
181 $plugoutobj->print_xml_usage(0);
182 }
183 else {
184 $plugoutobj->print_xml_usage(0, 1);
185 }
186
187 }
188 print STDERR "</PlugoutList>\n";
189 }
190 else {
191 &print_single_plugout($plugout_name, $xml, 1);
192 }
193
194
195}
196
197
198sub print_single_plugout {
199 my ($plugout_name, $xml, $header) = @_;
200 my $plugout;
201
202 push @$plugout,$plugout_name;
203
204 my $plugoutobj = &plugout::load_plugout($plugout);
205
206 if ($xml) {
207 $plugoutobj->print_xml_usage($header);
208 }
209 else {
210 gsprintf(STDERR, "\n{plugoutinfo.passing_options}\n\n");
211 gsprintf(STDERR, "{plugoutinfo.option_types}:\n\n");
212 gsprintf(STDERR, "{plugoutinfo.specific_options}\n\n");
213 gsprintf(STDERR, "{plugoutinfo.general_options}\n\n");
214 gsprintf(STDERR, "$plugout_name {plugoutinfo.info}:\n\n");
215
216 $plugoutobj->print_txt_usage();
217 }
218
219}
220
221&main ();
Note: See TracBrowser for help on using the repository browser.