[12334] | 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 |
|
---|
| 30 | use strict;
|
---|
| 31 | no strict 'subs'; # allow barewords (eg STDERR) as function arguments
|
---|
| 32 |
|
---|
| 33 | BEGIN {
|
---|
| 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 |
|
---|
| 41 | use plugout;
|
---|
| 42 | use util;
|
---|
| 43 | use gsprintf;
|
---|
| 44 | use printusage;
|
---|
| 45 | use parse2;
|
---|
| 46 |
|
---|
| 47 | my $arguments =
|
---|
[12639] | 48 | [ { 'name' => "collection",
|
---|
| 49 | 'desc' => "{plugoutinfo.collection}",
|
---|
[12334] | 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 |
|
---|
| 69 | my $options = { 'name' => "plugoutinfo.pl",
|
---|
| 70 | 'desc' => "{plugoutinfo.desc}",
|
---|
| 71 | 'args' => $arguments };
|
---|
| 72 |
|
---|
| 73 | sub gsprintf
|
---|
| 74 | {
|
---|
| 75 | return &gsprintf::gsprintf(@_);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 |
|
---|
| 79 | sub main {
|
---|
[12639] | 80 | my $collection = "";
|
---|
[12334] | 81 | my $xml = 0;
|
---|
| 82 | my $listall = 0;
|
---|
| 83 | my $describeall = 0;
|
---|
| 84 | my ($language, $encoding);
|
---|
| 85 |
|
---|
| 86 | my $hashParsingResult = {};
|
---|
[12545] | 87 | # general options available to all plugouts
|
---|
[12334] | 88 | my $unparsed_args = parse2::parse(\@ARGV,$arguments,$hashParsingResult,"allow_extra_options");
|
---|
| 89 |
|
---|
[12545] | 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 |
|
---|
[12334] | 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 |
|
---|
[12545] | 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
|
---|
[12615] | 132 | if(@ARGV && $ARGV[0] =~ /^\-+h/ )
|
---|
[12334] | 133 | {
|
---|
[12545] | 134 | PrintUsage::print_txt_usage($options, "{plugoutinfo.params}");
|
---|
| 135 | die "\n";
|
---|
[12334] | 136 | }
|
---|
| 137 |
|
---|
[12615] | 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) {
|
---|
[12334] | 140 | gsprintf(STDERR, "{plugoutinfo.no_plugout_name}\n\n");
|
---|
| 141 | PrintUsage::print_txt_usage($options, "{plugoutinfo.params}", 1);
|
---|
| 142 | die "\n";
|
---|
| 143 | }
|
---|
| 144 |
|
---|
[12615] | 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 |
|
---|
[14734] | 153 | my $plugout_name = shift (@ARGV);
|
---|
| 154 |
|
---|
| 155 | if (defined $plugout_name) {
|
---|
| 156 | $plugout_name =~ s/\.pm$//; # allow xxxPlugout.pm as the argument
|
---|
[12615] | 157 | }
|
---|
| 158 |
|
---|
[12639] | 159 | if ($collection ne "") {
|
---|
| 160 | $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collection);
|
---|
[12334] | 161 | } else {
|
---|
| 162 | $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[12629] | 165 | if ($listall || $describeall) {
|
---|
[12640] | 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);
|
---|
[12625] | 171 | }
|
---|
[12334] | 172 |
|
---|
[12640] | 173 | print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
|
---|
| 174 | print STDERR "<PlugoutList length=\"" . scalar(@plugout_list) . "\">\n";
|
---|
[14734] | 175 | foreach my $plugout_name (@plugout_list) {
|
---|
| 176 | $plugout_name =~ s/\.pm$//;
|
---|
| 177 | my $plugout;
|
---|
| 178 | push @$plugout,$plugout_name;
|
---|
[12640] | 179 | my $plugoutobj = &plugout::load_plugout ($plugout);
|
---|
| 180 | if ($describeall) {
|
---|
| 181 | $plugoutobj->print_xml_usage(0);
|
---|
[12334] | 182 | }
|
---|
[12640] | 183 | else {
|
---|
| 184 | $plugoutobj->print_xml_usage(0, 1);
|
---|
| 185 | }
|
---|
[14734] | 186 |
|
---|
[12334] | 187 | }
|
---|
[12640] | 188 | print STDERR "</PlugoutList>\n";
|
---|
[12334] | 189 | }
|
---|
| 190 | else {
|
---|
[14734] | 191 | &print_single_plugout($plugout_name, $xml, 1);
|
---|
[12334] | 192 | }
|
---|
[14734] | 193 |
|
---|
| 194 |
|
---|
[12334] | 195 | }
|
---|
| 196 |
|
---|
[12629] | 197 |
|
---|
[12334] | 198 | sub print_single_plugout {
|
---|
[14734] | 199 | my ($plugout_name, $xml, $header) = @_;
|
---|
| 200 | my $plugout;
|
---|
[12334] | 201 |
|
---|
[14734] | 202 | push @$plugout,$plugout_name;
|
---|
| 203 |
|
---|
| 204 | my $plugoutobj = &plugout::load_plugout($plugout);
|
---|
| 205 |
|
---|
[12334] | 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 {plugoutinfo.info}:\n\n");
|
---|
| 215 |
|
---|
| 216 | $plugoutobj->print_txt_usage();
|
---|
| 217 | }
|
---|
| 218 |
|
---|
| 219 | }
|
---|
| 220 |
|
---|
| 221 | &main ();
|
---|