| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
#!/usr/bin/perl |
|
2
|
|
|
|
|
|
|
###################### |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# Copyright (C) 2011 - 2015 TU Clausthal, Institut fuer Maschinenwesen, Joachim Langenbach |
|
5
|
|
|
|
|
|
|
# |
|
6
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
7
|
|
|
|
|
|
|
# it under the terms of the GNU General Public License as published by |
|
8
|
|
|
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or |
|
9
|
|
|
|
|
|
|
# (at your option) any later version. |
|
10
|
|
|
|
|
|
|
# |
|
11
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
12
|
|
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13
|
|
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14
|
|
|
|
|
|
|
# GNU General Public License for more details. |
|
15
|
|
|
|
|
|
|
# |
|
16
|
|
|
|
|
|
|
# You should have received a copy of the GNU General Public License |
|
17
|
|
|
|
|
|
|
# along with this program. If not, see . |
|
18
|
|
|
|
|
|
|
# |
|
19
|
|
|
|
|
|
|
###################### |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# Pod::Weaver infos |
|
22
|
|
|
|
|
|
|
# PODNAME: fm_create_help |
|
23
|
|
|
|
|
|
|
# ABSTRACT: Walks through an installation and tries to extract all options with informations into a database |
|
24
|
|
|
|
|
|
|
|
|
25
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
23
|
|
|
26
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
45
|
|
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
package CAD::Firemen::ParseHelp::Wildfire5; |
|
29
|
|
|
|
|
|
|
{ |
|
30
|
|
|
|
|
|
|
$CAD::Firemen::ParseHelp::Wildfire5::VERSION = '0.7.1'; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
1
|
|
|
1
|
|
5
|
use Exporter 'import'; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
37
|
|
|
33
|
|
|
|
|
|
|
our @EXPORT_OK = qw( |
|
34
|
|
|
|
|
|
|
extractHelpWildfire5 |
|
35
|
|
|
|
|
|
|
); |
|
36
|
|
|
|
|
|
|
|
|
37
|
1
|
|
|
1
|
|
4
|
use POSIX; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
5
|
|
|
38
|
1
|
|
|
1
|
|
3231
|
use Archive::Zip qw/ :ERROR_CODES :CONSTANTS/; |
|
|
1
|
|
|
|
|
82922
|
|
|
|
1
|
|
|
|
|
200
|
|
|
39
|
1
|
|
|
1
|
|
1087
|
use HTML::TreeBuilder; |
|
|
1
|
|
|
|
|
38976
|
|
|
|
1
|
|
|
|
|
12
|
|
|
40
|
1
|
|
|
1
|
|
6877
|
use IO::HTML; |
|
|
1
|
|
|
|
|
26187
|
|
|
|
1
|
|
|
|
|
58
|
|
|
41
|
1
|
|
|
1
|
|
437
|
use XML::LibXML; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
use Tie::File; |
|
43
|
|
|
|
|
|
|
use Term::ProgressBar; |
|
44
|
|
|
|
|
|
|
use CAD::Firemen; |
|
45
|
|
|
|
|
|
|
use CAD::Firemen::Common qw( |
|
46
|
|
|
|
|
|
|
strip |
|
47
|
|
|
|
|
|
|
testPassed |
|
48
|
|
|
|
|
|
|
testFailed |
|
49
|
|
|
|
|
|
|
); |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub getChildDivs { |
|
52
|
|
|
|
|
|
|
my $parent = shift; |
|
53
|
|
|
|
|
|
|
my @results = (); |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
if(!defined($parent) || (ref($parent) ne "HTML::Element")){ |
|
56
|
|
|
|
|
|
|
return @results; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
foreach my $elem ($parent->content_list()){ |
|
60
|
|
|
|
|
|
|
if(ref($elem) ne "HTML::Element"){ |
|
61
|
|
|
|
|
|
|
next; |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
if($elem->tag() eq "div"){ |
|
64
|
|
|
|
|
|
|
push(@results, $elem); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
return @results; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub extractHelpWildfire5 { |
|
71
|
|
|
|
|
|
|
my $tocUrl = shift; |
|
72
|
|
|
|
|
|
|
my $language = shift; |
|
73
|
|
|
|
|
|
|
my $cdbOptionsRef = shift; |
|
74
|
|
|
|
|
|
|
my %cdbOptions = %{$cdbOptionsRef}; |
|
75
|
|
|
|
|
|
|
my $verbose = shift; |
|
76
|
|
|
|
|
|
|
my $zipUrl = shift; |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# just to avoid unused warning in release tests |
|
79
|
|
|
|
|
|
|
$language = undef; |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
my %optionsInfo = (); |
|
82
|
|
|
|
|
|
|
my %optionsValue = (); |
|
83
|
|
|
|
|
|
|
my %optionsDefault = (); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
my $zip = undef; |
|
86
|
|
|
|
|
|
|
if(-e $zipUrl){ |
|
87
|
|
|
|
|
|
|
# catch file not exists error before Zip->new(), because Zip->new() gives ugly error messages |
|
88
|
|
|
|
|
|
|
$zip = Archive::Zip->new($zipUrl); |
|
89
|
|
|
|
|
|
|
if(!defined($zip)){ |
|
90
|
|
|
|
|
|
|
testFailed("Load help archive"); |
|
91
|
|
|
|
|
|
|
return ({}, {}, {}, {}); |
|
92
|
|
|
|
|
|
|
} |
|
93
|
|
|
|
|
|
|
else{ |
|
94
|
|
|
|
|
|
|
testPassed("Load help archive"); |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
my @toc; |
|
100
|
|
|
|
|
|
|
if(tie(@toc, 'Tie::File', $tocUrl)){ |
|
101
|
|
|
|
|
|
|
testPassed("Open TOC"); |
|
102
|
|
|
|
|
|
|
# the linebreak is needed to uncolor Term::ProgressBar |
|
103
|
|
|
|
|
|
|
print "\n"; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
else{ |
|
106
|
|
|
|
|
|
|
testFailed("Open TOC"); |
|
107
|
|
|
|
|
|
|
if($verbose > 0){ |
|
108
|
|
|
|
|
|
|
print "TOC Url: ". $tocUrl ."\n"; |
|
109
|
|
|
|
|
|
|
} |
|
110
|
|
|
|
|
|
|
return ({}, {}, {}, {}); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
# enabling autoflush to print parse status |
|
113
|
|
|
|
|
|
|
my $lines = scalar(@toc); |
|
114
|
|
|
|
|
|
|
my $progress = Term::ProgressBar->new({name => "Collecting infos", count => $lines}); |
|
115
|
|
|
|
|
|
|
$progress->minor(0); |
|
116
|
|
|
|
|
|
|
my $i = 0; |
|
117
|
|
|
|
|
|
|
my %errors = (); |
|
118
|
|
|
|
|
|
|
foreach my $line (@toc){ |
|
119
|
|
|
|
|
|
|
my $line = strip($line);# |
|
120
|
|
|
|
|
|
|
if($line =~ m/label=\"([^\"]+)\" path=\"([^(?:\"|#)]+)/){ |
|
121
|
|
|
|
|
|
|
my $opt = uc($1); |
|
122
|
|
|
|
|
|
|
my $file = $2; |
|
123
|
|
|
|
|
|
|
# exclude directories, only file paths are used here |
|
124
|
|
|
|
|
|
|
if($file =~ m/\/$/){ |
|
125
|
|
|
|
|
|
|
next; |
|
126
|
|
|
|
|
|
|
} |
|
127
|
|
|
|
|
|
|
# some options exists several times, therefore only use the first entry found |
|
128
|
|
|
|
|
|
|
# (Last condition) |
|
129
|
|
|
|
|
|
|
if(exists($cdbOptions{$opt}) && ($file ne "") && (!exists($optionsInfo{$opt}))){ |
|
130
|
|
|
|
|
|
|
# option found and file path also not empty |
|
131
|
|
|
|
|
|
|
my $htmlTree = HTML::TreeBuilder->new(); |
|
132
|
|
|
|
|
|
|
if(defined($zip)){ |
|
133
|
|
|
|
|
|
|
my $content = $zip->contents($file); |
|
134
|
|
|
|
|
|
|
if(!$content){ |
|
135
|
|
|
|
|
|
|
$errors{$opt} = "Could not extract file ". $file; |
|
136
|
|
|
|
|
|
|
next; |
|
137
|
|
|
|
|
|
|
} |
|
138
|
|
|
|
|
|
|
if(utf8::is_utf8($content)){ |
|
139
|
|
|
|
|
|
|
$content = utf8::decode($content); |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
$htmlTree->parse($content); |
|
142
|
|
|
|
|
|
|
} |
|
143
|
|
|
|
|
|
|
else{ |
|
144
|
|
|
|
|
|
|
next; |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# do some cleanup on the tree |
|
148
|
|
|
|
|
|
|
$htmlTree->eof(); |
|
149
|
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
# first check whether we've got the correct file with help of title |
|
151
|
|
|
|
|
|
|
my $element = $htmlTree->find('title'); |
|
152
|
|
|
|
|
|
|
if(!$element){ |
|
153
|
|
|
|
|
|
|
$errors{$opt} = "Could not find "; |
|
154
|
|
|
|
|
|
|
next; |
|
155
|
|
|
|
|
|
|
} |
|
156
|
|
|
|
|
|
|
my @contents = $element->content_refs_list(); |
|
157
|
|
|
|
|
|
|
my $title = uc(${$contents[0]}); |
|
158
|
|
|
|
|
|
|
if($title ne $opt){ |
|
159
|
|
|
|
|
|
|
$errors{$opt} = "Title are not matching (Expected: ". $opt .", Got: ". $title .")"; |
|
160
|
|
|
|
|
|
|
next; |
|
161
|
|
|
|
|
|
|
} |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
$element = $htmlTree->look_down("_tag", "div"); |
|
164
|
|
|
|
|
|
|
my @elements = getChildDivs($element); |
|
165
|
|
|
|
|
|
|
if(scalar(@elements) != 2){ |
|
166
|
|
|
|
|
|
|
if(scalar(@elements) == 3){ |
|
167
|
|
|
|
|
|
|
# fixing those with empty second div |
|
168
|
|
|
|
|
|
|
if($elements[1]->as_trimmed_text() eq ""){ |
|
169
|
|
|
|
|
|
|
$elements[1] = $elements[2]; |
|
170
|
|
|
|
|
|
|
pop(@elements); |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
else{ |
|
173
|
|
|
|
|
|
|
$errors{$opt} = "Second div-container of three within the first div container is not empty."; |
|
174
|
|
|
|
|
|
|
next; |
|
175
|
|
|
|
|
|
|
} |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
else{ |
|
178
|
|
|
|
|
|
|
$errors{$opt} = "Wrong number of div-containers within the first div container (Expected: 2, Got: ". scalar(@elements) .")"; |
|
179
|
|
|
|
|
|
|
next; |
|
180
|
|
|
|
|
|
|
} |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
# the first div container contains the option name and the second |
|
183
|
|
|
|
|
|
|
# contains the values and the description |
|
184
|
|
|
|
|
|
|
@elements = getChildDivs($elements[1]); |
|
185
|
|
|
|
|
|
|
if(scalar(@elements) < 1){ |
|
186
|
|
|
|
|
|
|
$errors{$opt} = "Wrong number of div-containers within the second div container (Expected: >=1, Got: ". scalar(@elements) .")"; |
|
187
|
|
|
|
|
|
|
next; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
# get values |
|
191
|
|
|
|
|
|
|
my @values = (); |
|
192
|
|
|
|
|
|
|
# the text of the options div (like ansi * , iso) |
|
193
|
|
|
|
|
|
|
my $text = $elements[0]->as_trimmed_text(); |
|
194
|
|
|
|
|
|
|
my @tmp = split(/,/, $text); |
|
195
|
|
|
|
|
|
|
foreach my $value (@tmp){ |
|
196
|
|
|
|
|
|
|
# if we have replaced a *, this is the default value, |
|
197
|
|
|
|
|
|
|
# because only the default value contains a star |
|
198
|
|
|
|
|
|
|
if($value =~ s/\*//){ |
|
199
|
|
|
|
|
|
|
$optionsDefault{$opt} = uc(strip($value)); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
$value = uc(strip($value)); |
|
202
|
|
|
|
|
|
|
push(@values, $value); |
|
203
|
|
|
|
|
|
|
} |
|
204
|
|
|
|
|
|
|
$optionsValue{$opt} = [ @values ]; |
|
205
|
|
|
|
|
|
|
# check extracted values against those from cdb |
|
206
|
|
|
|
|
|
|
if(scalar($optionsValue{$opt}) == scalar(keys(%{$cdbOptions{$opt}}))){ |
|
207
|
|
|
|
|
|
|
$errors{$opt} = "Found different values for option ". $opt ."(Expected: ". scalar(keys(%{$cdbOptions{$opt}})) .", Got: ". scalar($optionsValue{$opt}) .")"; |
|
208
|
|
|
|
|
|
|
} |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
# get info (all div after the values div, contains description |
|
211
|
|
|
|
|
|
|
$optionsInfo{$opt} = ""; |
|
212
|
|
|
|
|
|
|
for(my $j = 1; $j < scalar(@elements); $j++){ |
|
213
|
|
|
|
|
|
|
$optionsInfo{$opt} .= $elements[$j]->as_trimmed_text() ."\n"; |
|
214
|
|
|
|
|
|
|
} |
|
215
|
|
|
|
|
|
|
# remove last linebreak |
|
216
|
|
|
|
|
|
|
$optionsInfo{$opt} = strip($optionsInfo{$opt}); |
|
217
|
|
|
|
|
|
|
# remove wide characters |
|
218
|
|
|
|
|
|
|
$optionsInfo{$opt} =~ s/[^[:ascii:]]+//g; |
|
219
|
|
|
|
|
|
|
$htmlTree->delete(); |
|
220
|
|
|
|
|
|
|
} |
|
221
|
|
|
|
|
|
|
} |
|
222
|
|
|
|
|
|
|
$i++; |
|
223
|
|
|
|
|
|
|
$progress->update($i); |
|
224
|
|
|
|
|
|
|
} |
|
225
|
|
|
|
|
|
|
if($i < $lines){ |
|
226
|
|
|
|
|
|
|
$progress->update($lines); |
|
227
|
|
|
|
|
|
|
} |
|
228
|
|
|
|
|
|
|
print "\n"; # print line break to keep the progress bar of the last step |
|
229
|
|
|
|
|
|
|
untie @toc; |
|
230
|
|
|
|
|
|
|
return (\%optionsInfo, \%optionsValue, \%optionsDefault, \%errors); |
|
231
|
|
|
|
|
|
|
} |
|
232
|
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
1; |
|
234
|
|
|
|
|
|
|
|
|
235
|
|
|
|
|
|
|
__END__ |