| 1 | #!/usr/bin/perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | ###################### | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # Copyright (C) 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 <http://www.gnu.org/licenses/>. | ||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||
| 19 | ###################### | ||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # Pod::Weaver infos | ||||||||||||||||||||||||||||||||||||||||||
| 22 | # ABSTRACT: Shared functions to exctract options and their values, default value and descriptions (Creo 3 and later). | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | package CAD::Firemen::ParseHelp::Creo3; | ||||||||||||||||||||||||||||||||||||||||||
| 28 | { | ||||||||||||||||||||||||||||||||||||||||||
| 29 | 4 | $CAD::Firemen::ParseHelp::Creo3::VERSION = '0.7.2'; | |||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 4 | ▶ | use Exporter 'import'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 4 | our @EXPORT_OK = qw( | |||||||||||||||||||||||||||||||||||||||||
| 33 | extractHelpCreo3 | ||||||||||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 4 | ▶ | use POSIX; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 4 | ▶ | use Tie::File; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 4 | ▶ | use utf8; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 39 | 4 | ▶ | use Term::ProgressBar; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 40 | 4 | ▶ | use JSON::Parse 'parse_json'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 4 | ▶ | use IO::HTML; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 42 | 4 | ▶ | use HTML::TreeBuilder 5 -weak; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 4 | ▶ | use File::Basename; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 4 | ▶ | use CAD::Firemen; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 4 | ▶ | use CAD::Firemen::Common qw( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | strip | ||||||||||||||||||||||||||||||||||||||||||
| 47 | testPassed | ||||||||||||||||||||||||||||||||||||||||||
| 48 | testFailed | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 4 | ); | |||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub findOptionPage { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
findOptionPage: not called CC=20 SCAR=60.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | my $cdbOptions = shift; | |||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | my $optionsInfo = shift; | |||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | my $optionsValues = shift; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | my $optionsDefault = shift; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | my $errors = shift; | |||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 0 | my $app = shift; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $verbose = shift; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | ▶ | if(!defined($verbose)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | $verbose = 0; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | 0 | my @toc; | |||||||||||||||||||||||||||||||||||||||||
| 65 | 0 | ▶ | if(!tie(@toc, 'Tie::File', $file, recsep => "\n")){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 0 | return (0, "Could not open file to find option page: ". $file); | |||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | my ($fileName, $filePath, $fileSuffix) = fileparse($file); | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | # just to avoid unused warning in release tests | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | $fileName = undef; | |||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | $fileSuffix = undef; | |||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | my $lines = scalar(@toc); | |||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | my $progress = Term::ProgressBar->new({name => "Parsing index file for app ". $app, count => $lines}); | |||||||||||||||||||||||||||||||||||||||||
| 77 | 0 | $progress->minor(0); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 0 | my $json; | |||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | foreach my $line (@toc){ | |||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $line = strip($line); | |||||||||||||||||||||||||||||||||||||||||
| 82 | 0 | ▶ | if($i != 0 && substr($line, 0, 1) ne ";"){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$i != 0 and substr($line, 0, 1) ne ";"
MC/DC0%0/2
$i != 0 and substr($line, 0, 1) ne ";"
$i != 0
substr($line, 0, 1) ne ";"
Truth table0%0/3
A and B
A= $i != 0B= substr($line, 0, 1) ne ";"
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | $json .= $line ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $progress->update($i); | |||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | if($i < $lines){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $progress->update($lines); | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my $jsonContent = parse_json($json); | |||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | ▶ | if(!$jsonContent || !exists($jsonContent->{"words"}) || !exists($jsonContent->{"pages"})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$jsonContent and exists $jsonContent->{"words"} and exists $jsonContent->{"pages"}
$jsonContent and exists $jsonContent->{"words"}
MC/DC0%0/3
$jsonContent and exists $jsonContent->{"words"} and exists $jsonContent->{"pages"}
$jsonContent
exists $jsonContent->{"words"}
exists $jsonContent->{"pages"}
Truth table0%0/4
A and B and C
A= $jsonContentB= exists $jsonContent->{"words"}C= exists $jsonContent->{"pages"}
| |||||||||||||||||||||||||||||||||||||||||||
| 95 | 0 | return (0, "Could not parse content of ". $file); | |||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | my $items = scalar(keys(%{$jsonContent->{"words"}})); | |||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | $progress = Term::ProgressBar->new({name => "Processing ". $items ." keywords and ". scalar(keys(@{$jsonContent->{"pages"}})) ." pages for app ". $app, count => $items}); | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | $progress->minor(0); | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 102 | 0 | foreach my $key (keys(%{$jsonContent->{"words"}})){ | |||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | foreach my $option (keys(%{$cdbOptions})){ | |||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | if(!exists($optionsInfo->{$option})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if($key =~ m/$option/i){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if(scalar($jsonContent->{"words"}->{$key}) < 2){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | return (0, "Malformed index found --> Stopping here"); | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | for(my $i = 0; $i < scalar(@{$jsonContent->{"words"}->{$key}}) - 1; $i = $i + 2){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my $pagesRow = $jsonContent->{"words"}->{$key}->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 112 | 0 | my $pagesColumn = $jsonContent->{"words"}->{$key}->[$i + 1] - 1; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | ▶ | if($pagesColumn != 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | # skip all references, which does not reference the html page (first column in $pages | ||||||||||||||||||||||||||||||||||||||||||
| 115 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my $page = $jsonContent->{"pages"}->[$pagesRow]->[$pagesColumn]; | |||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $result= extractHelp($cdbOptions, $optionsInfo, $optionsValues, $optionsDefault, $errors, $option, $filePath ."/". $page, $verbose); | |||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | ▶ | if($verbose > 2){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | ▶ | if($result){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | print $option ." --> ". $page ." OK\n"; | |||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||
| 123 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | print $option ." --> ". $page ." - NOT FOUND\n"; | |||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 0 | $progress->update($i); | |||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | ▶ | if($i < $items){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 135 | 0 | $progress->update($items); | |||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | print "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 0 | return $errors; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub extractHelp { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extractHelp: not called CC=23 SCAR=63.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | my $cdbOptions = shift; | |||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $optionsInfo = shift; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | my $optionsValues = shift; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 0 | my $optionsDefault = shift; | |||||||||||||||||||||||||||||||||||||||||
| 146 | 0 | my $errors = shift; | |||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | my $option = uc(shift); | |||||||||||||||||||||||||||||||||||||||||
| 148 | 0 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 149 | 0 | my $verbose = shift; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | ▶ | if(!defined($verbose)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $verbose = 0; | |||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 0 | my $optionLowered = lc($option); | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 0 | my @htmlContent; | |||||||||||||||||||||||||||||||||||||||||
| 157 | #if(!tie(@htmlContent, 'Tie::File', $file, recsep => "\x0D\x0A", discipline => ':encoding(utf8)')){ | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | ▶ | if(!tie(@htmlContent, 'Tie::File', $file)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | if(!exists($errors->{$option})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | $errors->{$option} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 0 | $errors->{$option} .= "Could not open HTML file ". $file; | |||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my $htmlTree = HTML::TreeBuilder->new; | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | ▶ | if(!$htmlTree->parse_file(html_file($file))){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | ▶ | if(!exists($errors->{$option})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | $errors->{$option} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $errors->{$option} .= "Could not open file ". $file; | |||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | my $optionFound = 0; | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my $regexSection = qr/<div class=\"Section_Title\" id=\"([^\"]+)\"><span class=\"option\">$optionLowered<\/span><\/div>/; | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | my @sectionTitles = $htmlTree->look_down("_tag" => "div", "class" => "Section_Title"); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | if(scalar(@sectionTitles) < 1 && $verbose > 2){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @sectionTitles < 1 and $verbose > 2
MC/DC0%0/2
scalar @sectionTitles < 1 and $verbose > 2
scalar @sectionTitles < 1
$verbose > 2
Truth table0%0/3
A and B
A= scalar @sectionTitles < 1B= $verbose > 2
| |||||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | print "Found no section titles in file ". $file ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | foreach my $sectionTitle (@sectionTitles){ | |||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | ▶ | if($sectionTitle->as_HTML() =~ m/$regexSection/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 182 | 0 | my $id = $1; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 0 | $id =~ s/(.+)_[0-9]+/$1/; | |||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | $optionFound = 1; | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | my @bodies = $htmlTree->look_down("_tag" => "div", "id" => qr/$id[_0-9]+/); | |||||||||||||||||||||||||||||||||||||||||
| 187 | 0 | foreach my $body (@bodies){ | |||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my @values = $body->as_HTML() =~ m/<span class=\"codeph\">([^>]+)<\/span>/g; | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | ▶ | if(scalar(@values) > 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | for(my $i = 0; $i < scalar(@values); $i++){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | $values[$i] = strip($values[$i]); | |||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||
| 193 | 0 | $optionsValues->{$option} = [ @values ]; | |||||||||||||||||||||||||||||||||||||||||
| 194 | # check extracted values against those from cdb | ||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | if(scalar($optionsValues->{$option}) == scalar(keys(%{$cdbOptions->{$option}}))){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | if(!exists($errors->{$option})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | $errors->{$option} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 198 | } | ||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | $errors->{$option} .= "Found different values for option ". $option ."(Expected: ". scalar(keys(%{$cdbOptions->{$option}})) .", Got: ". scalar($optionsValues->{$option}) .")"; | |||||||||||||||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if($body->as_HTML() =~ m/<span class=\"codeph\">([^>]+)<\/span><span class=\"Superscript\">\*<\/span>/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | # match default option | ||||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $optionsDefault->{$option} = uc(strip($1)); | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||
| 206 | else{ | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if(!exists($optionsInfo->{$option})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | $optionsInfo->{$option} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 0 | $optionsInfo->{$option} .= " ". $body->as_text_trimmed(); | |||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | $optionsInfo->{$option} = strip($optionsInfo->{$option}); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | last; | |||||||||||||||||||||||||||||||||||||||||
| 215 | } | ||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | if(!$optionFound){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | my @divs = $htmlTree->look_down("_tag" => "div"); | |||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if(scalar(@divs) < 1 && $verbose > 2){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
scalar @divs < 1 and $verbose > 2
MC/DC0%0/2
scalar @divs < 1 and $verbose > 2
scalar @divs < 1
$verbose > 2
Truth table0%0/3
A and B
A= scalar @divs < 1B= $verbose > 2
| |||||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | print "Found no divs in file ". $file ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my $regexOption = qr/<span class=\"option\">$optionLowered<\/span>[\):\s]{0,}([^<]+)/; | |||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | foreach my $div (@divs){ | |||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | if($div->as_HTML() =~ m/$regexOption/){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | $optionFound = 1; | |||||||||||||||||||||||||||||||||||||||||
| 226 | 0 | ▶ | if(!exists($optionsInfo->{$option})){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 227 | 0 | $optionsInfo->{$option} = ""; | |||||||||||||||||||||||||||||||||||||||||
| 228 | } | ||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $optionsInfo->{$option} .= " ". $1; | |||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | $optionsInfo->{$option} = strip($optionsInfo->{$option}); | |||||||||||||||||||||||||||||||||||||||||
| 231 | } | ||||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | return $optionFound; | |||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | ▶ | sub extractHelpCreo3 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extractHelpCreo3: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | my $directory = shift; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | my $language = shift; | |||||||||||||||||||||||||||||||||||||||||
| 240 | 0 | my $cdbOptions = shift; | |||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | my $verbose = shift; | |||||||||||||||||||||||||||||||||||||||||
| 242 | 0 | my %optionsInfo = (); | |||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | my %optionsValues = (); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 0 | my %optionsDefault = (); | |||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | my %errors = (); | |||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | ▶ | if(!-d $directory){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | 0 | testFailed("Examine help structure"); | |||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | if($verbose > 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | print "Directory does not exist: ". $directory ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | return ({}, {}, {}, {}); | |||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||
| 254 | 0 | $directory =~ s/[\/\\]+$//; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | my $dir; | |||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if(!opendir($dir, $directory)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | testFailed("Examine help structure"); | |||||||||||||||||||||||||||||||||||||||||
| 258 | 0 | ▶ | if($verbose > 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | print "Could not open directory: ". $directory ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return ({}, {}, {}, {}); | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | ▶ | while(my $entry = readdir($dir)){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | 0 | ▶ | if($entry !~ m/^\./){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 0 | my $subDir = $directory ."/". $entry; | |||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | ▶ | if(-d $subDir){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | my @tmp = split(/_/, $entry); | |||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | ▶ | if(scalar(@tmp) < 1){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | ▶ | if($verbose > 1){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | print "Error determining app of directory entry ". $entry ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | my $app = $tmp[scalar(@tmp) - 1]; | |||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $file = $subDir ."/". $language ."/". $app ."_sx.js"; | |||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | if(!-f $file){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if($verbose > 1){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | print "Index file does not exists: ". $file ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | exit 1; | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | 0 | my $errors = findOptionPage($cdbOptions, \%optionsInfo, \%optionsValues, \%optionsDefault, \%errors, $file, $app, $verbose); | |||||||||||||||||||||||||||||||||||||||||
| 283 | 0 | ▶ | if(scalar(keys(%{$errors})) > 0){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | if($verbose > 1){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 285 | 0 | print "The following errors occured parsing directory ". $subDir .":\n"; | |||||||||||||||||||||||||||||||||||||||||
| 286 | 0 | foreach my $option (sort(keys(%{$errors}))){ | |||||||||||||||||||||||||||||||||||||||||
| 287 | 0 | print " ". $option .": ". $errors->{$option} ."\n"; | |||||||||||||||||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | closedir($dir); | |||||||||||||||||||||||||||||||||||||||||
| 295 | 0 | return (\%optionsInfo, \%optionsValues, \%optionsDefault, \%errors); | |||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||
| 298 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | __END__ | ||||||||||||||||||||||||||||||||||||||||||