source: trunk/gsdl/bin/script/pluginfo.pl@ 6054

Last change on this file since 6054 was 5882, checked in by davidb, 21 years ago

'cpan' added to perllib path to help plugins and classifiers find supporting
files

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 4.8 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
30# @revision 09/05/02 Added XML usage information flag - John Thompson
31
32BEGIN {
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/plugins");
38}
39
40use plugin;
41use util;
42use parsargv;
43use gsprintf;
44use printusage;
45
46
47my $arguments =
48 [ { 'name' => "collect",
49 'desc' => "{pluginfo.collect}",
50 'type' => "string",
51 'reqd' => "no" },
52 { 'name' => "xml",
53 'desc' => "{scripts.xml}",
54 'type' => "flag",
55 'reqd' => "no" },
56 { 'name' => "language",
57 'desc' => "{scripts.language}",
58 'type' => "string",
59 'reqd' => "no" } ];
60
61my $options = { 'name' => "pluginfo.pl",
62 'desc' => "{pluginfo.desc}",
63 'args' => $arguments };
64
65
66sub lookup_string
67{
68 return &gsprintf::lookup_string($language, shift(@_));
69}
70
71
72sub print_txt_usage
73{
74 local $language = shift(@_);
75
76 local $programname = $options->{'name'};
77 local $programargs = $options->{'args'};
78
79 # Find the length of the longest option string
80 local $descoffset = 0;
81 if (defined($programargs)) {
82 $descoffset = &PrintUsage::find_longest_option_string($programargs);
83 }
84
85 # Produce the usage information using the data structure above
86 print STDERR $programname . ": " . &lookup_string($options->{'desc'}) . "\n\n";
87 print STDERR " " . &lookup_string("{common.usage}") . ": $programname";
88 print STDERR " " . &lookup_string("{pluginfo.params}") . "\n\n";
89
90 # Display the program options, if there are some
91 if (defined($programargs)) {
92 # Calculate the column offset of the option descriptions
93 local $optiondescoffset = $descoffset + 2; # 2 spaces between options & descriptions
94
95 print STDERR " " . &lookup_string("{common.options}") . ":\n";
96
97 # Display the program options
98 &PrintUsage::print_options_txt($language, $programargs, $optiondescoffset);
99 }
100}
101
102
103
104sub main {
105 my $collect = "";
106 my $xml = 0;
107 my $language = ""; # Will display in the default language if not set
108
109 if (!parsargv::parse(\@ARGV,
110 q^collect/.*/^, \$collect,
111 q^xml^, \$xml,
112 q^language/.*/^, \$language))
113 {
114 &print_txt_usage($language);
115 die "\n";
116 }
117
118 my $plugin = shift (@ARGV);
119 if (!defined $plugin || $plugin eq "") {
120 print STDERR &lookup_string("{pluginfo.no_plugin_name}") . "\n\n";
121 &print_txt_usage($language);
122 die "\n";
123 }
124
125 if ($collect ne "") {
126 $ENV{'GSDLCOLLECTDIR'} = &util::filename_cat ($ENV{'GSDLHOME'}, "collect", $collect);
127 } else {
128 $ENV{'GSDLCOLLECTDIR'} = $ENV{'GSDLHOME'};
129 }
130
131 my $pluginfo = &plugin::load_plugins ([[$plugin]]);
132 my $plugobj = shift @$pluginfo;
133
134 if ($xml) {
135 $plugobj->print_xml_usage($language);
136 }
137 else {
138 print STDERR "\n$plugin " . &lookup_string("{pluginfo.info}") . ":\n\n";
139 print STDERR &lookup_string("{pluginfo.passing_options}") . "\n\n";
140 print STDERR &lookup_string("{pluginfo.option_types}") . ":\n\n";
141 print STDERR &lookup_string("{pluginfo.specific_options}") . "\n\n";
142 print STDERR &lookup_string("{pluginfo.general_options}") . "\n\n";
143
144 $plugobj->print_txt_usage($language);
145 }
146}
147
148
149# this causes us to automatically send output to a pager, if one is
150# set, AND our output is going to a terminal
151# active state perl on windows doesn't do open(handle, "-|");
152if ($ENV{'GSDLOS'} !~ /windows/ && -t STDOUT) {
153 my $pager = $ENV{"PAGER"};
154 if (! $pager) {$pager="(less || more)"}
155 $pid = open(STDIN, "-|"); # this does a fork... see man perlipc(1)
156 if (!defined $pid) {
157 print STDERR "pluginfo.pl - can't fork: $!";
158 } else {
159 if ($pid != 0) { # parent (ie forking) process. child gets 0
160 exec ($pager);
161 }
162 }
163 open(STDERR,">&STDOUT"); # so it's easier to pipe output
164}
165
166
167&main ();
Note: See TracBrowser for help on using the repository browser.