1 | ## Most basic plugin, just handles parsing the arguments and printing out descriptions. Used for plugins and Extractor plugins
|
---|
2 |
|
---|
3 | package PrintInfo;
|
---|
4 |
|
---|
5 | BEGIN {
|
---|
6 | die "GSDLHOME not set\n" unless defined $ENV{'GSDLHOME'};
|
---|
7 | }
|
---|
8 |
|
---|
9 | eval {require bytes};
|
---|
10 |
|
---|
11 | # suppress the annoying "subroutine redefined" warning that various
|
---|
12 | # plugins cause under perl 5.6
|
---|
13 | $SIG{__WARN__} = sub {warn($_[0]) unless ($_[0] =~ /Subroutine\s+\S+\sredefined/)};
|
---|
14 |
|
---|
15 | use strict;
|
---|
16 | no strict 'subs';
|
---|
17 |
|
---|
18 | use gsprintf 'gsprintf';
|
---|
19 | use parse2;
|
---|
20 | use printusage;
|
---|
21 |
|
---|
22 | my $arguments = [];
|
---|
23 |
|
---|
24 | my $options = { 'name' => "PrintInfo",
|
---|
25 | 'desc' => "{PrintInfo.desc}",
|
---|
26 | 'abstract' => "yes",
|
---|
27 | 'inherits' => "no",
|
---|
28 | 'args' => $arguments };
|
---|
29 |
|
---|
30 |
|
---|
31 | sub new
|
---|
32 | {
|
---|
33 | my $class = shift (@_);
|
---|
34 | my ($pluginlist,$args,$hashArgOptLists) = @_;
|
---|
35 | my $plugin_name = (defined $pluginlist->[0]) ? $pluginlist->[0] : $class;
|
---|
36 |
|
---|
37 | if ($plugin_name eq $class) {
|
---|
38 | push(@{$hashArgOptLists->{"ArgList"}},@{$arguments});
|
---|
39 | push(@{$hashArgOptLists->{"OptList"}},$options);
|
---|
40 | }
|
---|
41 | my $self = {};
|
---|
42 | $self->{'outhandle'} = STDERR;
|
---|
43 | $self->{'option_list'} = $hashArgOptLists->{"OptList"};
|
---|
44 | $self->{"info_only"} = 0;
|
---|
45 |
|
---|
46 | # Check if gsdlinfo is in the argument list or not - if it is, don't parse
|
---|
47 | # the args, just return the object.
|
---|
48 | foreach my $strArg (@{$args})
|
---|
49 | {
|
---|
50 | if($strArg eq "-gsdlinfo")
|
---|
51 | {
|
---|
52 | $self->{"info_only"} = 1;
|
---|
53 | return bless $self, $class;
|
---|
54 | }
|
---|
55 | }
|
---|
56 |
|
---|
57 | if(parse2::parse($args,$hashArgOptLists->{"ArgList"},$self) == -1)
|
---|
58 | {
|
---|
59 | my $classTempClass = bless $self, $class;
|
---|
60 | print STDERR "<BadPlugin p=$plugin_name>\n";
|
---|
61 | &gsprintf(STDERR, "\n{BasPlug.bad_general_option}\n", $plugin_name);
|
---|
62 | $classTempClass->print_txt_usage(""); # Use default resource bundle
|
---|
63 | die "\n";
|
---|
64 | }
|
---|
65 |
|
---|
66 | delete $self->{"info_only"};
|
---|
67 | # else parsing was successful.
|
---|
68 |
|
---|
69 | $self->{'plugin_type'} = $plugin_name;
|
---|
70 |
|
---|
71 | return bless $self, $class;
|
---|
72 |
|
---|
73 | }
|
---|
74 |
|
---|
75 | #sub init {
|
---|
76 | #}
|
---|
77 |
|
---|
78 | sub get_arguments
|
---|
79 | {
|
---|
80 | my $self = shift(@_);
|
---|
81 | my $optionlistref = $self->{'option_list'};
|
---|
82 | my @optionlist = @$optionlistref;
|
---|
83 | my $pluginoptions = pop(@$optionlistref);
|
---|
84 | my $pluginarguments = $pluginoptions->{'args'};
|
---|
85 | return $pluginarguments;
|
---|
86 | }
|
---|
87 |
|
---|
88 |
|
---|
89 | sub print_xml_usage
|
---|
90 | {
|
---|
91 | my $self = shift(@_);
|
---|
92 | my $header = shift(@_);
|
---|
93 | my $high_level_information_only = shift(@_);
|
---|
94 |
|
---|
95 | # XML output is always in UTF-8
|
---|
96 | gsprintf::output_strings_in_UTF8;
|
---|
97 |
|
---|
98 | if ($header) {
|
---|
99 | &PrintUsage::print_xml_header("plugin");
|
---|
100 | }
|
---|
101 | $self->print_xml($high_level_information_only);
|
---|
102 | }
|
---|
103 |
|
---|
104 |
|
---|
105 | sub print_xml
|
---|
106 | {
|
---|
107 | my $self = shift(@_);
|
---|
108 | my $high_level_information_only = shift(@_);
|
---|
109 |
|
---|
110 | my $optionlistref = $self->{'option_list'};
|
---|
111 | my @optionlist = @$optionlistref;
|
---|
112 | my $pluginoptions = shift(@$optionlistref);
|
---|
113 | return if (!defined($pluginoptions));
|
---|
114 |
|
---|
115 | # Find the process and block default expressions in the plugin arguments
|
---|
116 | my $process_exp = "";
|
---|
117 | my $block_exp = "";
|
---|
118 | if (defined($pluginoptions->{'args'})) {
|
---|
119 | foreach my $option (@{$pluginoptions->{'args'}}) {
|
---|
120 | if ($option->{'name'} eq "process_exp") {
|
---|
121 | $process_exp = $option->{'deft'};
|
---|
122 | }
|
---|
123 | if ($option->{'name'} eq "block_exp") {
|
---|
124 | $block_exp = $option->{'deft'};
|
---|
125 | }
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 | gsprintf(STDERR, "<PlugInfo>\n");
|
---|
130 | gsprintf(STDERR, " <Name>$pluginoptions->{'name'}</Name>\n");
|
---|
131 | my $desc = gsprintf::lookup_string($pluginoptions->{'desc'});
|
---|
132 | $desc =~ s/</&lt;/g; # doubly escaped
|
---|
133 | $desc =~ s/>/&gt;/g;
|
---|
134 | gsprintf(STDERR, " <Desc>$desc</Desc>\n");
|
---|
135 | gsprintf(STDERR, " <Abstract>$pluginoptions->{'abstract'}</Abstract>\n");
|
---|
136 | gsprintf(STDERR, " <Inherits>$pluginoptions->{'inherits'}</Inherits>\n");
|
---|
137 | gsprintf(STDERR, " <Processes>$process_exp</Processes>\n");
|
---|
138 | gsprintf(STDERR, " <Blocks>$block_exp</Blocks>\n");
|
---|
139 | gsprintf(STDERR, " <Explodes>" . ($pluginoptions->{'explodes'} || "no") . "</Explodes>\n");
|
---|
140 | # adding new option that works with replace_srcdoc_with_html.pl
|
---|
141 | gsprintf(STDERR, " <SourceReplaceable>" . ($pluginoptions->{'srcreplaceable'} || "no") . "</SourceReplaceable>\n");
|
---|
142 | unless (defined($high_level_information_only)) {
|
---|
143 | gsprintf(STDERR, " <Arguments>\n");
|
---|
144 | if (defined($pluginoptions->{'args'})) {
|
---|
145 | &PrintUsage::print_options_xml($pluginoptions->{'args'});
|
---|
146 | }
|
---|
147 | gsprintf(STDERR, " </Arguments>\n");
|
---|
148 |
|
---|
149 | # Recurse up the plugin hierarchy
|
---|
150 | $self->print_xml();
|
---|
151 | }
|
---|
152 | gsprintf(STDERR, "</PlugInfo>\n");
|
---|
153 | }
|
---|
154 |
|
---|
155 |
|
---|
156 | sub print_txt_usage
|
---|
157 | {
|
---|
158 | my $self = shift(@_);
|
---|
159 | # Print the usage message for a plugin (recursively)
|
---|
160 | my $descoffset = $self->determine_description_offset(0);
|
---|
161 | $self->print_plugin_usage($descoffset, 1);
|
---|
162 | }
|
---|
163 |
|
---|
164 |
|
---|
165 | sub determine_description_offset
|
---|
166 | {
|
---|
167 | my $self = shift(@_);
|
---|
168 | my $maxoffset = shift(@_);
|
---|
169 |
|
---|
170 | my $optionlistref = $self->{'option_list'};
|
---|
171 | my @optionlist = @$optionlistref;
|
---|
172 | my $pluginoptions = shift(@$optionlistref);
|
---|
173 | return $maxoffset if (!defined($pluginoptions));
|
---|
174 |
|
---|
175 | # Find the length of the longest option string of this plugin
|
---|
176 | my $pluginargs = $pluginoptions->{'args'};
|
---|
177 | if (defined($pluginargs)) {
|
---|
178 | my $longest = &PrintUsage::find_longest_option_string($pluginargs);
|
---|
179 | if ($longest > $maxoffset) {
|
---|
180 | $maxoffset = $longest;
|
---|
181 | }
|
---|
182 | }
|
---|
183 |
|
---|
184 | # Recurse up the plugin hierarchy
|
---|
185 | $maxoffset = $self->determine_description_offset($maxoffset);
|
---|
186 | $self->{'option_list'} = \@optionlist;
|
---|
187 | return $maxoffset;
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | sub print_plugin_usage
|
---|
192 | {
|
---|
193 | my $self = shift(@_);
|
---|
194 | my $descoffset = shift(@_);
|
---|
195 | my $isleafclass = shift(@_);
|
---|
196 |
|
---|
197 | my $optionlistref = $self->{'option_list'};
|
---|
198 | my @optionlist = @$optionlistref;
|
---|
199 | my $pluginoptions = shift(@$optionlistref);
|
---|
200 | return if (!defined($pluginoptions));
|
---|
201 |
|
---|
202 | my $pluginname = $pluginoptions->{'name'};
|
---|
203 | my $pluginargs = $pluginoptions->{'args'};
|
---|
204 | my $plugindesc = $pluginoptions->{'desc'};
|
---|
205 |
|
---|
206 | # Produce the usage information using the data structure above
|
---|
207 | if ($isleafclass) {
|
---|
208 | if (defined($plugindesc)) {
|
---|
209 | gsprintf(STDERR, "$plugindesc\n\n");
|
---|
210 | }
|
---|
211 | gsprintf(STDERR, " {common.usage}: plugin $pluginname [{common.options}]\n\n");
|
---|
212 | }
|
---|
213 |
|
---|
214 | # Display the plugin options, if there are some
|
---|
215 | if (defined($pluginargs)) {
|
---|
216 | # Calculate the column offset of the option descriptions
|
---|
217 | my $optiondescoffset = $descoffset + 2; # 2 spaces between options & descriptions
|
---|
218 |
|
---|
219 | if ($isleafclass) {
|
---|
220 | gsprintf(STDERR, " {common.specific_options}:\n");
|
---|
221 | }
|
---|
222 | else {
|
---|
223 | gsprintf(STDERR, " {common.general_options}:\n", $pluginname);
|
---|
224 | }
|
---|
225 |
|
---|
226 | # Display the plugin options
|
---|
227 | &PrintUsage::print_options_txt($pluginargs, $optiondescoffset);
|
---|
228 | }
|
---|
229 |
|
---|
230 | # Recurse up the plugin hierarchy
|
---|
231 | $self->print_plugin_usage($descoffset, 0);
|
---|
232 | $self->{'option_list'} = \@optionlist;
|
---|
233 | }
|
---|
234 |
|
---|
235 | 1;
|
---|
236 |
|
---|
237 |
|
---|