source: main/tags/2.60/gsdl/bin/script/pluginfo.pl@ 25196

Last change on this file since 25196 was 9375, checked in by jrm21, 19 years ago

minor fix for getting encoding from LC_ALL environment variable

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1#!/usr/bin/perl -w
2
3###########################################################################
4#
5# pluginfo.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 plugin
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/plugins");
39}
40
41use plugin;
42use util;
43use parsargv;
44use gsprintf;
45use printusage;
46
47
48my $arguments =
49 [ { 'name' => "collect",
50 'desc' => "{pluginfo.collect}",
51 'type' => "string",
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
66my $options = { 'name' => "pluginfo.pl",
67 'desc' => "{pluginfo.desc}",
68 'args' => $arguments };
69
70sub gsprintf
71{
72 return &gsprintf::gsprintf(@_);
73}
74
75
76sub main {
77 my $collect = "";
78 my $xml = 0;
79 my $listall = 0;
80
81 my ($language, $encoding);
82
83 if (!parsargv::parse(\@ARGV,
84 q^collect/.*/^, \$collect,
85 q^xml^, \$xml,
86 q^listall^, \$listall,
87 q^language/.*/^, \$language))
88 {
89 PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
90 die "\n";
91 }
92
93 # if language wasn't specified, see if it is set in the environment
94 # (LC_ALL or LANG)
95 if (!$language && ($_=$ENV{'LC_ALL'} or $_=$ENV{'LANG'})) {
96 m/^([^\.]+)\.?(.*)/;
97 $language=$1;
98 $encoding=$2; # might be undef...
99# gsprintf::load_language* thinks "fr" is completely different to "fr_FR"...
100 $language =~ s/_.*$//;
101 }
102
103 # If $language has been set, load the appropriate resource bundle
104 # (Otherwise, the default resource bundle will be loaded automatically)
105 if ($language) {
106 gsprintf::load_language_specific_resource_bundle($language);
107 if ($encoding) {
108 $encoding =~ tr/-/_/;
109 $encoding = lc($encoding);
110 $encoding =~ s/utf_8/utf8/; # special
111 $gsprintf::specialoutputencoding=$encoding;
112 }
113 }
114
115 my $plugin = shift (@ARGV);
116 if (($listall == 0) && (!defined $plugin || $plugin eq "")) {
117 gsprintf(STDERR, "{pluginfo.no_plugin_name}\n\n");
118 PrintUsage::print_txt_usage($options, "{pluginfo.params}", 1);
119 die "\n";
120 }
121
122 if ($collect ne "") {
123 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
124 } else {
125 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
126 }
127
128 if ($listall) {
129 my $plugin_dir = &util::filename_cat($ENV{'GSDLCOLLECTDIR'},"perllib","plugins");
130
131 if (!opendir (INDIR, $plugin_dir)) {
132 print STDERR "pluginfo.pl: could not open directory $plugin_dir\n";
133 } else {
134 my @plugin_list = grep (/Plug\.pm$/, readdir (INDIR));
135 closedir (INDIR);
136
137
138 if ($xml) {
139 my $num_plugins = scalar(@plugin_list);
140
141 print STDERR "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
142 print STDERR "<!DOCTYPE PluginList [\n";
143 print STDERR " <!ELEMENT PluginList (PluginName*)>\n";
144 print STDERR " <!ELEMENT PlugName (#PCDATA)>\n";
145 print STDERR " <!ATTLIST PluginList\n";
146 print STDERR " length CDATA #REQUIRED>\n";
147 print STDERR "]>\n";
148
149 print STDERR "<PluginList length=\"$num_plugins\">\n";
150 map { print STDERR " <PluginName>$_</PluginName>\n"; } @plugin_list;
151 print STDERR "</PluginList>\n";
152
153 }
154 else {
155 print STDERR join(" ",@plugin_list), "\n";
156 }
157 }
158
159 }
160 else {
161
162 my $pluginfo = &plugin::load_plugins ([[$plugin]]);
163 my $plugobj = shift @$pluginfo;
164
165 if ($xml) {
166 $plugobj->print_xml_usage();
167 }
168 else {
169 gsprintf(STDERR, "\n{pluginfo.passing_options}\n\n");
170 gsprintf(STDERR, "{pluginfo.option_types}:\n\n");
171 gsprintf(STDERR, "{pluginfo.specific_options}\n\n");
172 gsprintf(STDERR, "{pluginfo.general_options}\n\n");
173 gsprintf(STDERR, "$plugin {pluginfo.info}:\n\n");
174
175 $plugobj->print_txt_usage();
176 }
177 }
178}
179
180
181# this causes us to automatically send output to a pager, if one is
182# set, AND our output is going to a terminal
183# active state perl on windows doesn't do open(handle, "-|");
184if ($ENV{'GSDLOS'} !~ /windows/ && -t STDOUT) {
185 my $pager = $ENV{"PAGER"};
186 if (! $pager) {$pager="(less || more)"}
187 my $pid = open(STDIN, "-|"); # this does a fork... see man perlipc(1)
188 if (!defined $pid) {
189 gsprintf(STDERR, "pluginfo.pl - can't fork: $!");
190 } else {
191 if ($pid != 0) { # parent (ie forking) process. child gets 0
192 exec ($pager);
193 }
194 }
195 open(STDERR,">&STDOUT"); # so it's easier to pipe output
196}
197
198
199&main ();
Note: See TracBrowser for help on using the repository browser.