1eval 'exec perl -wS $0 ${1+\"$@\"}' 2 if 0; 3 4#************************************************************************* 5# 6# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7# 8# Copyright 2000, 2010 Oracle and/or its affiliates. 9# 10# OpenOffice.org - a multi-platform office productivity suite 11# 12# This file is part of OpenOffice.org. 13# 14# OpenOffice.org is free software: you can redistribute it and/or modify 15# it under the terms of the GNU Lesser General Public License version 3 16# only, as published by the Free Software Foundation. 17# 18# OpenOffice.org is distributed in the hope that it will be useful, 19# but WITHOUT ANY WARRANTY; without even the implied warranty of 20# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21# GNU Lesser General Public License version 3 for more details 22# (a copy is included in the LICENSE file that accompanied this code). 23# 24# You should have received a copy of the GNU Lesser General Public License 25# version 3 along with OpenOffice.org. If not, see 26# <http://www.openoffice.org/license.html> 27# for a copy of the LGPLv3 License. 28# 29#************************************************************************* 30 31BEGIN 32{ 33 # Adding the path of this script file to the include path in the hope 34 # that all used modules can be found in it. 35 $0 =~ /^(.*)[\/\\]/; 36 push @INC, $1; 37 # print "PATH: " . $1 . "\n"; 38} 39 40# my $e; 41# foreach $e (keys %ENV) 42# { 43# print "$e := $ENV{$e}" . "\n"; 44# } 45 46use strict; 47use graphical_compare; 48use ConvwatchHelper; 49use filehelper; 50use timehelper; 51use loghelper; 52 53use Cwd; 54use File::Basename; 55use Getopt::Long; 56use English; # $OSNAME, ... 57use File::Path; 58use Cwd 'chdir'; 59 60our $help; # Help option flag 61our $version; # Version option flag 62# our $test; 63 64# our $MAJOR; 65# our $MINOR; 66# our $cwsname; 67our $pool; 68our $document; 69our $creatortype; 70our $prepareonly = 0; 71our $force; 72our $verbose = 0; 73our $show = 0; 74our $connectionstring; 75 76# Prototypes 77sub print_usage(*); 78sub prepare(); 79sub CompareFiles($$); 80 81# flush STDOUT 82# my $old_handle = select (STDOUT); # "select" STDOUT and save # previously selected handle 83# $| = 1; # perform flush after each write to STDOUT 84# select ($old_handle); # restore previously selected handle 85 86$OUTPUT_AUTOFLUSH=1; # works only if use English is used. 87 88our $version_info = 'compare.pl'; 89 90GetOptions( 91# "MAJOR=s" => \$MAJOR, 92# "MINOR=s" => \$MINOR, 93# "cwsname=s" => \$cwsname, 94 "pool=s" => \$pool, 95 "document=s" => \$document, 96 "creatortype=s" => \$creatortype, 97 "prepareonly=s" => \$prepareonly, 98 "connectionstring=s" => \$connectionstring, 99 100 "force" => \$force, 101 "verbose" => \$verbose, 102 "show" => \$show, 103 104# "test" => \$test, 105 "help" => \$help, 106 "version" => \$version 107 ); 108 109if ($help) 110{ 111 print_usage(*STDOUT); 112 exit(0); 113} 114# Check for version option 115if ($version) 116{ 117 print STDERR "$version_info\n"; 118 exit(0); 119} 120 121if ($prepareonly) 122{ 123 $force=1; 124} 125 126prepare(); 127if ($connectionstring) 128{ 129 setConnectionString($connectionstring); 130} 131 132my $sDocumentPool = appendPath(getProjectRoot(), "document-pool"); 133# print "ProjectRoot: " . getProjectRoot() . "\n"; 134if ($ENV{DOCUMENTPOOL}) 135{ 136 if ( -d $ENV{DOCUMENTPOOL}) 137 { 138 print "overwrite default Documentpool: '$sDocumentPool'\n"; 139 print " with \$ENV{DOCUMENTPOOL}: $ENV{DOCUMENTPOOL}\n"; 140 $sDocumentPool = $ENV{DOCUMENTPOOL}; 141 } 142 else 143 { 144 print "Given \$DOCUMENTPOOL doesn't exist.\n"; 145 } 146} 147 148my $err = 0; 149my $nCompareTime = getTime(); 150 151# if we want to check one file, give -pool and -document 152# if we want to check the whole pool, give -pool 153# if we want to check all, call without parameters 154if ($pool) 155{ 156 if ($document) 157 { 158 $err = SingleDocumentCompare( $sDocumentPool, 159 $pool, 160 $document, 161 $creatortype, 162 $prepareonly, 163 $show 164 ); 165 } 166 else 167 { 168 $err = CompareFiles($sDocumentPool, $pool); 169 } 170} 171else 172{ 173 local *DIR; 174 if (opendir (DIR, $sDocumentPool)) # Directory oeffnen 175 { 176 my $myfile; 177 while ($myfile = readdir(DIR)) 178 { # ein filename holen 179 if ($myfile eq "." || 180 $myfile eq "..") 181 { 182 next; 183 } 184 my $sDocumentPath = appendPath($sDocumentPool, $myfile); 185 if ( -d $sDocumentPath ) 186 { 187 $err += CompareFiles($sDocumentPool, $myfile); 188 } 189 elsif ( -f $sDocumentPath ) 190 { 191 print "Warning: the file '$myfile' will not compared.\n"; 192 } 193 } 194 closedir(DIR); 195 } 196 # my $sPool = "eis-chart"; 197 # $err += CompareFiles($sDocumentPool, "eis-chart"); 198 # $err += CompareFiles($sDocumentPool, "eis-impress"); 199 # $err += CompareFiles($sDocumentPool, "eis-writer"); 200 # $err += CompareFiles($sDocumentPool, "eis-calc"); 201 202} 203 204printTime(endTime($nCompareTime)); 205exit ($err); 206 207# ------------------------------------------------------------------------------ 208 209sub CompareFiles($$) 210{ 211 my $sDocumentPath = shift; 212 my $sPool = shift; 213 my %aFailedHash; 214 my $startdir = appendPath($sDocumentPath, $sPool); 215 216 local *DIR; 217 if (opendir (DIR, $startdir)) # Directory oeffnen 218 { 219 my $myfile; 220 while ($myfile = readdir(DIR)) 221 { # ein filename holen 222 if ($myfile eq "knownissues.xcl") 223 { 224 next; 225 } 226 my $sAbsoluteFile = appendPath($startdir, $myfile); 227 if (-f $sAbsoluteFile) 228 { 229 my $nIssue; 230 my $sIssueText; 231 ($nIssue, $sIssueText) = checkForKnownIssue($startdir, $myfile); 232 if ($nIssue == 0) 233 { 234 $err = SingleDocumentCompare( 235 # "/net/so-gfxcmp-documents.germany.sun.com/export/gfxcmp/document-pool", # $documentpoolpath, 236 $sDocumentPool, 237 $sPool, # $documentpool, 238 $myfile, # $documentname); 239 $creatortype, # $destinationcreatortype, 240 $prepareonly, 241 $show 242 ); 243 $aFailedHash{$myfile} = $err; 244 } 245 else 246 { 247 print "$myfile [KNOWN ISSUE: #$sIssueText#]\n"; 248 } 249 } 250 } 251 closedir(DIR); 252 } 253 254 print "***** State for graphical compare of pool: '$sPool' ******\n"; 255 my $nErrorCount = 0; 256 my $file; 257 foreach $file (keys %aFailedHash) 258 { 259 if ($aFailedHash{$file} != 0) 260 { 261 print "Failed: $file\n"; 262 $nErrorCount++; 263 } 264 } 265 print "Whole unit: "; 266 if ($nErrorCount > 0) 267 { 268 print "PASSED.FAILED\n"; 269 } 270 else 271 { 272 print "PASSED.OK\n"; 273 } 274 print "************************************************************\n"; 275 return $nErrorCount; 276} 277# ------------------------------------------------------------------------------ 278# return issue number if file exists in knownissues.xcl file 279sub checkForKnownIssue($$) 280{ 281 my $startdir = shift; 282 my $myfile = shift; 283 284 if ($force) 285 { 286 return 0,""; 287 } 288 289 my $sKnownIssueFile = appendPath($startdir, "knownissues.xcl"); 290 my $sIssueText = "unknown"; 291 local *ISSUES; 292 my $nIssue = 0; 293 my $sCurrentSection; 294 295 if (open(ISSUES, $sKnownIssueFile)) 296 { 297 my $line; 298 while ($line = <ISSUES>) 299 { 300 chomp($line); 301 if ($line =~ /\[(.*)\]/ ) 302 { 303 $sCurrentSection = $1; 304 next; 305 } 306 if ($sCurrentSection eq $creatortype) 307 { 308 if ($line =~ /\#\#\# (.*) \#\#\#/ ) 309 { 310 $sIssueText = $1; 311 } 312 if ($line =~ /^${myfile}$/ ) 313 { 314 $nIssue = 1; 315 last; 316 } 317 } 318 } 319 close(ISSUES); 320 } 321 return $nIssue, $sIssueText; 322} 323# ------------------------------------------------------------------------------ 324sub prepare() 325{ 326 # directory structure: 327 # documents will be found in 328 # ../document-pool/eis-tests 329 330 # references will be found in 331 # ../references/unxlngi/eis-tests 332 # ../references/wntmsci/eis-tests 333 334 # output goes to 335 # ../unxlngi6.pro/misc 336 337 if ($verbose) 338 { 339 setVerbose(); 340 } 341 342 # TEST 343 if (!$ENV{INPATH}) 344 { 345 if ($OSNAME eq "linux") 346 { 347 # just for debug 348 setINPATH("unxlngi6.pro"); 349 } 350 } 351 else 352 { 353 setINPATH($ENV{INPATH}); 354 } 355 356 if (! $creatortype) 357 { 358 $creatortype= "ps"; 359 } 360 361 my $cwd = getcwd(); 362 print "Current Directory: $cwd\n" if ($verbose); 363 my $sProjectBase; 364 if ($ENV{PRJ}) 365 { 366 # print "cwd:=$cwd\n"; 367 # print "PRJ:=$ENV{PRJ}\n"; 368 $sProjectBase = appendPath($cwd, $ENV{PRJ}); 369 } 370 else 371 { 372 $sProjectBase = dirname($cwd); 373 } 374 if ($OSNAME eq "cygwin") 375 { 376 $sProjectBase = `cygpath -w $sProjectBase`; 377 chomp($sProjectBase); 378 $sProjectBase = unixpath($sProjectBase); 379 # print "cygwin patch \$sProjectBase := $sProjectBase\n"; 380 } 381 # print "Project base path: $sProjectBase\n"; 382 setProjectRoot($sProjectBase); 383 384 385 # TEST TEST TEST 386 # exit (0); 387} 388# ------------------------------------------------------------------------------ 389sub print_usage(*) 390{ 391 local *HANDLE = $_[0]; 392 my $tool_name = basename($0); 393 394 print(HANDLE <<END_OF_USAGE); 395 396Usage: $tool_name [OPTIONS] 397 398 -pool Give pool name out of document-pool directory. 399 But all documents list in knownissues.xcl will not check. 400 -document Give a single document to test, the known issue list will ignored. 401 -creatortype=s s:ps create postscript files via print to file. 402 s:pdf create PDF file via export to pdf. 403 -h, --help Print this help, then exit 404 -v, --version Print version number, then exit 405 406END_OF_USAGE 407; 408} 409