1#*************************************************************************
2#
3# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4#
5# Copyright 2000, 2010 Oracle and/or its affiliates.
6#
7# OpenOffice.org - a multi-platform office productivity suite
8#
9# This file is part of OpenOffice.org.
10#
11# OpenOffice.org is free software: you can redistribute it and/or modify
12# it under the terms of the GNU Lesser General Public License version 3
13# only, as published by the Free Software Foundation.
14#
15# OpenOffice.org is distributed in the hope that it will be useful,
16# but WITHOUT ANY WARRANTY; without even the implied warranty of
17# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18# GNU Lesser General Public License version 3 for more details
19# (a copy is included in the LICENSE file that accompanied this code).
20#
21# You should have received a copy of the GNU Lesser General Public License
22# version 3 along with OpenOffice.org.  If not, see
23# <http://www.openoffice.org/license.html>
24# for a copy of the LGPLv3 License.
25#
26#*************************************************************************
27
28package installer::ziplist;
29
30use installer::existence;
31use installer::exiter;
32use installer::globals;
33use installer::logger;
34use installer::parameter;
35use installer::remover;
36use installer::systemactions;
37
38#################################################
39# Getting data from path file and zip list file
40#################################################
41
42sub getproductblock
43{
44	my ($fileref, $search, $inheritance) = @_;
45
46	my @searchblock = ();
47	my $searchexists = 0;
48	my $record = 0;
49	my $count = 0;
50	my $line;
51    my $inh = $inheritance ? '(?::\s*(\S+)\s*)?' : "";
52    my $parent;
53
54	for ( my $i = 0; $i <= $#{$fileref}; $i++ )
55	{
56		$line = ${$fileref}[$i];
57
58		if ( $line =~ /^\s*\Q$search\E\s*$inh$/i )		# case insensitive
59		{
60			$record = 1;
61			$searchexists = 1;
62            $parent = $1 if $inheritance;
63		}
64
65		if ($record)
66		{
67			push(@searchblock, $line);
68		}
69
70		if ( ($record) && ($line =~ /\{/) )
71		{
72			$count++;
73		}
74
75		if ( ($record) && ($line =~ /\}/) )
76		{
77			$count--;
78		}
79
80		if ( ($record) && ($line =~ /\}/) && ( $count == 0 ) )
81		{
82			$record = 0;
83		}
84	}
85
86	if (( ! $searchexists ) && ( $search ne $installer::globals::globalblock ))
87	{
88		if ($search eq $installer::globals::product )
89		{
90			installer::exiter::exit_program("ERROR: Product $installer::globals::product not defined in $installer::globals::ziplistname", "getproductblock");
91		}
92		elsif ($search eq $installer::globals::compiler )
93		{
94			installer::exiter::exit_program("ERROR: Compiler $installer::globals::compiler not defined in $installer::globals::pathfilename", "getproductblock");
95		}
96		else	# this is not possible
97		{
98			installer::exiter::exit_program("ERROR: Unknown value for $search in getproductblock()", "getproductblock");
99		}
100	}
101
102	return (\@searchblock, $parent);
103}
104
105###############################################
106# Analyzing the settings in the zip list file
107###############################################
108
109sub analyze_settings_block
110{
111	my ($blockref) = @_;
112
113	my @newsettingsblock = ();
114	my $compilerstring = "";
115	my $record = 1;
116	my $counter = 0;
117
118	# Allowed values in settings block:
119	# "Settings", "Variables", "unix" (for destination path and logfile)
120	# Furthermore allowed values are $installer::globals::build (srx645) and $installer::globals::compiler (pro and nonpro (unxsols4.pro))
121
122	# Comment line in settings block begin with "#" or ";"
123
124	if ( $installer::globals::pro )
125	{
126		$compilerstring = $installer::globals::compiler . ".pro";
127	}
128	else
129	{
130		$compilerstring = $installer::globals::compiler;
131	}
132
133	for ( my $i = 0; $i <= $#{$blockref}; $i++ )
134	{
135		my $line = ${$blockref}[$i];
136		my $nextline = "";
137
138		if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
139
140		# removing comment lines
141
142		if (($line =~ /^\s*\#/) || ($line =~ /^\s*\;/))
143		{
144			next;
145		}
146
147		# complete blocks of unknows strings are not recorded
148
149		if ((!($line =~ /^\s*\Q$compilerstring\E\s*$/i)) &&
150			(!($line =~ /^\s*\Q$installer::globals::build\E\s*$/i)) &&
151			(!($line =~ /^\s*\bSettings\b\s*$/i)) &&
152			(!($line =~ /^\s*\bVariables\b\s*$/i)) &&
153			(!($line =~ /^\s*\bunix\b\s*$/i)) &&
154			($nextline =~ /^\s*\{\s*$/i))
155		{
156			$record = 0;
157			next;			# continue with next $i
158		}
159
160		if (!( $record ))
161		{
162			if ($line =~ /^\s*\{\s*$/i)
163			{
164				$counter++;
165			}
166
167			if ($line =~ /^\s*\}\s*$/i)
168			{
169				$counter--;
170			}
171
172			if ($counter == 0)
173			{
174				$record = 1;
175				next;	# continue with next $i
176			}
177		}
178
179		if ($record)
180		{
181			push(@newsettingsblock, $line);
182		}
183	}
184
185	return \@newsettingsblock;
186}
187
188########################################
189# Settings in zip list file
190########################################
191
192sub get_settings_from_ziplist
193{
194	my ($blockref) = @_;
195
196	my @allsettings = ();
197	my $isvariables = 0;
198	my $counter = 0;
199	my $variablescounter = 0;
200
201	# Take all settings from the settings block
202	# Do not take the variables from the settings block
203	# If a setting is defined more than once, take the
204	# setting with the largest counter (open brackets)
205
206	for ( my $i = 0; $i <= $#{$blockref}; $i++ )
207	{
208		my $line = ${$blockref}[$i];
209		my $nextline = "";
210
211		if ( ${$blockref}[$i+1] ) { $nextline = ${$blockref}[$i+1]; }
212
213		if (($line =~ /^\s*\S+\s*$/i) &&
214			($nextline =~ /^\s*\{\s*$/i) &&
215			(!($line =~ /^\s*Variables\s*$/i)))
216		{
217			next;
218		}
219
220		if ($line =~ /^\s*Variables\s*$/i)
221		{
222			# This is a block of variables
223
224			$isvariables = 1;
225			next;
226		}
227
228		if ($line =~ /^\s*\{\s*$/i)
229		{
230			if ($isvariables)
231			{
232				$variablescounter++;
233			}
234			else
235			{
236				$counter++;
237			}
238
239			next;
240		}
241
242		if ($line =~ /^\s*\}\s*$/i)
243		{
244			if ($isvariables)
245			{
246				$variablescounter--;
247
248				if ($variablescounter == 0)
249				{
250					$isvariables = 0;
251				}
252			}
253			else
254			{
255				$counter--;
256			}
257
258			next;
259		}
260
261		if ($isvariables)
262		{
263			next;
264		}
265
266		installer::remover::remove_leading_and_ending_whitespaces(\$line);
267
268		$line .= "\t##$counter##\n";
269
270		push(@allsettings, $line);
271	}
272
273	return \@allsettings;
274}
275
276#######################################
277# Variables from zip list file
278#######################################
279
280sub get_variables_from_ziplist
281{
282	my ($blockref) = @_;
283
284	my @allvariables = ();
285	my $isvariables = 0;
286	my $counter = 0;
287	my $variablescounter = 0;
288	my $countersum = 0;
289
290	# Take all variables from the settings block
291	# Do not take the other settings from the settings block
292	# If a variable is defined more than once, take the
293	# variable with the largest counter (open brackets)
294
295	for ( my $i = 0; $i <= $#{$blockref}; $i++ )
296	{
297		my $line = ${$blockref}[$i];
298		my $nextline = ${$blockref}[$i+1];
299
300		if ($line =~ /^\s*Variables\s*$/i)
301		{
302			# This is a block of variables
303
304			$isvariables = 1;
305			next;
306		}
307
308		if ($line =~ /^\s*\{\s*$/i)
309		{
310			if ($isvariables)
311			{
312				$variablescounter++;
313			}
314			else
315			{
316				$counter++;
317			}
318
319			next;
320		}
321
322		if ($line =~ /^\s*\}\s*$/i)
323		{
324			if ($isvariables)
325			{
326				$variablescounter--;
327
328				if ($variablescounter == 0)
329				{
330					$isvariables = 0;
331				}
332			}
333			else
334			{
335				$counter--;
336			}
337
338			next;
339		}
340
341		if (!($isvariables))
342		{
343			next;
344		}
345
346		$countersum = $counter + $variablescounter;
347
348		installer::remover::remove_leading_and_ending_whitespaces(\$line);
349
350		$line .= "\t##$countersum##\n";
351
352		push(@allvariables, $line);
353	}
354
355	return \@allvariables;
356}
357
358#######################################################################
359# Removing multiple variables and settings, defined in zip list file
360#######################################################################
361
362sub remove_multiples_from_ziplist
363{
364	my ($blockref) = @_;
365
366	# remove all definitions of settings and variables
367	# that occur more than once in the zip list file.
368	# Take the one with the most open brackets. This
369	# number is stored at the end of the string.
370
371	my @newarray = ();
372	my @itemarray = ();
373	my ($line, $itemname, $itemnumber);
374
375	# first collecting all variables and settings names
376
377	for ( my $i = 0; $i <= $#{$blockref}; $i++ )
378	{
379		$line = ${$blockref}[$i];
380
381		if ($line =~ /^\s*\b(\S*)\b\s+.*\#\#\d+\#\#\s*$/i)
382		{
383			$itemname = $1;
384		}
385
386		if (! installer::existence::exists_in_array($itemname, \@itemarray))
387		{
388			push(@itemarray, $itemname);
389		}
390	}
391
392	# and now all $items can be selected with the highest number
393
394	for ( my $i = 0; $i <= $#itemarray; $i++ )
395	{
396		$itemname = $itemarray[$i];
397
398		my $itemnumbermax = 0;
399		my $printline = "";
400
401		for ( my $j = 0; $j <= $#{$blockref}; $j++ )
402		{
403			$line = ${$blockref}[$j];
404
405			if ($line =~ /^\s*\Q$itemname\E\s+.*\#\#(\d+)\#\#\s*$/)
406			{
407				$itemnumber = $1;
408
409				if ($itemnumber >= $itemnumbermax)
410				{
411					$printline = $line;
412					$itemnumbermax = $itemnumber;
413				}
414			}
415		}
416
417		# removing the ending number from the printline
418		# and putting it into the array
419
420		$printline =~ s/\#\#\d+\#\#//;
421		installer::remover::remove_leading_and_ending_whitespaces(\$line);
422		push(@newarray, $printline);
423	}
424
425	return \@newarray;
426}
427
428#########################################################
429# Reading one variable defined in the zip list file
430#########################################################
431
432sub getinfofromziplist
433{
434	my ($blockref, $variable) = @_;
435
436	my $searchstring = "";
437	my $line;
438
439	for ( my $i = 0; $i <= $#{$blockref}; $i++ )
440	{
441		$line = ${$blockref}[$i];
442
443		if ( $line =~ /^\s*\Q$variable\E\s+(.+?)\s*$/ )	# "?" for minimal matching
444		{
445			$searchstring = $1;
446			last;
447		}
448	}
449
450	return \$searchstring;
451}
452
453####################################################
454# Replacing variables in include path
455####################################################
456
457sub replace_all_variables_in_pathes
458{
459	my ( $patharrayref, $variableshashref ) = @_;
460
461	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
462	{
463		my $line = ${$patharrayref}[$i];
464
465		my $key;
466
467		foreach $key (keys %{$variableshashref})
468		{
469			my $value = $variableshashref->{$key};
470
471			if (( $line =~ /\{$key\}/ ) && ( $value eq "" )) { $line = ".\n"; }
472
473			$line =~ s/\{\Q$key\E\}/$value/g;
474		}
475
476		${$patharrayref}[$i] = $line;
477	}
478}
479
480####################################################
481# Replacing minor in include path
482####################################################
483
484sub replace_minor_in_pathes
485{
486	my ( $patharrayref ) = @_;
487
488	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
489	{
490		my $line = ${$patharrayref}[$i];
491
492		if ( ! defined $ENV{CWS_WORK_STAMP} and defined $ENV{UPDMINOR} )
493#		if ( $installer::globals::minor )
494		{
495			$line =~ s/\{minor\}/$installer::globals::minor/g;
496			# no difference for minor and minornonpre (ToDo ?)
497			$line =~ s/\{minornonpre\}/$installer::globals::minor/g;
498		}
499		else	# building without a minor
500		{
501			$line =~ s/\.\{minor\}//g;
502			$line =~ s/\.\{minornonpre\}//g;
503		}
504
505		${$patharrayref}[$i] = $line;
506	}
507}
508
509####################################################
510# Replacing packagetype in include path
511####################################################
512
513sub replace_packagetype_in_pathes
514{
515	my ( $patharrayref ) = @_;
516
517	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
518	{
519		my $line = ${$patharrayref}[$i];
520
521		if (( $installer::globals::installertypedir ) && ( $line =~ /\{pkgtype\}/ ))
522		{
523			$line =~ s/\{pkgtype\}/$installer::globals::installertypedir/g;
524		}
525
526		${$patharrayref}[$i] = $line;
527	}
528}
529
530####################################################
531# Removing ending separators in pathes
532####################################################
533
534sub remove_ending_separator
535{
536	my ( $patharrayref ) = @_;
537
538	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
539	{
540		my $line = ${$patharrayref}[$i];
541
542		installer::remover::remove_ending_pathseparator(\$line);
543
544		$line =~ s/\s*$//;
545		$line = $line . "\n";
546
547		${$patharrayref}[$i] = $line;
548	}
549}
550
551####################################################
552# Replacing languages in include path
553####################################################
554
555sub replace_languages_in_pathes
556{
557	my ( $patharrayref, $languagesref ) = @_;
558
559	installer::logger::include_header_into_logfile("Replacing languages in include pathes:");
560
561	my @patharray = ();
562	my $infoline = "";
563
564	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
565	{
566		my $line = ${$patharrayref}[$i];
567
568		if ( $line =~ /\$\(LANG\)/ )
569		{
570			my $originalline = $line;
571			my $newline = "";
572
573			for ( my $j = 0; $j <= $#{$languagesref}; $j++ )
574			{
575				my $language = ${$languagesref}[$j];
576				$line =~ s/\$\(LANG\)/$language/g;
577				push(@patharray ,$line);
578				$newdir = $line;
579				$line = $originalline;
580
581				installer::remover::remove_leading_and_ending_whitespaces(\$newline);
582
583				# Is it necessary to refresh the global array, containing all files of all include pathes?
584				if ( -d $newdir )
585				{
586					# Checking if $newdir is empty
587					if ( ! installer::systemactions::is_empty_dir($newdir) )
588					{
589						$installer::globals::refresh_includepathes = 1;
590						$infoline = "Directory $newdir exists and is not empty. Refreshing global file array is required.\n";
591						push( @installer::globals::logfileinfo, $infoline);
592					}
593					else
594					{
595						$infoline = "Directory $newdir is empty. No refresh of global file array required.\n";
596						push( @installer::globals::logfileinfo, $infoline);
597					}
598				}
599				else
600				{
601					$infoline = "Directory $newdir does not exist. No refresh of global file array required.\n";
602					push( @installer::globals::logfileinfo, $infoline);
603				}
604			}
605		}
606		else		# not language dependent include path
607		{
608			push(@patharray ,$line);
609		}
610	}
611
612	return \@patharray;
613}
614
615#####################################################
616# Collecting all files from all include paths
617#####################################################
618
619sub list_all_files_from_include_path
620{
621	my ( $patharrayref) = @_;
622
623	installer::logger::include_header_into_logfile("Include pathes:");
624
625	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
626	{
627		my $path = ${$patharrayref}[$i];
628		installer::remover::remove_leading_and_ending_whitespaces(\$path);
629		my $infoline = "$path\n";
630		push( @installer::globals::logfileinfo, $infoline);
631	}
632
633	push( @installer::globals::logfileinfo, "\n");
634
635	return \@filesarray;
636}
637
638#####################################################
639# Collecting all files from all include paths
640#####################################################
641
642sub set_manufacturer
643{
644	my ($allvariables) = @_;
645
646	my $openofficeproductname = "OpenOffice.org";
647	my $sunname = "";
648
649
650	if ( $allvariables->{'OPENSOURCE'} && $allvariables->{'OPENSOURCE'} == 1 )
651	{
652		$installer::globals::isopensourceproduct = 1;
653		$installer::globals::manufacturer = $openofficeproductname;
654		$installer::globals::longmanufacturer = $openofficeproductname;
655	}
656	else
657	{
658		$installer::globals::isopensourceproduct = 0;
659		if (( $allvariables->{'DEFINEDMANUFACTURER'} ) && ( $allvariables->{'DEFINEDMANUFACTURER'} ne "" )) { $sunname = $allvariables->{'DEFINEDMANUFACTURER'}; }
660		else { installer::exiter::exit_program("ERROR: Property DEFINEDMANUFACTURER has to be set for this product!", "set_manufacturer"); }
661		$installer::globals::manufacturer = $sunname;
662		$installer::globals::longmanufacturer = $sunname;
663	}
664
665	$allvariables->{'MANUFACTURER'} = $installer::globals::manufacturer;
666}
667
668##############################################################
669# A ProductVersion has to be defined. If it is not set in
670# zip.lst, it is set now to "1"
671##############################################################
672
673sub set_default_productversion_if_required
674{
675	my ($allvariables) = @_;
676
677	if (!($allvariables->{'PRODUCTVERSION'}))
678	{
679		$allvariables->{'PRODUCTVERSION'} = 1;	# FAKE
680	}
681
682	# Creating differentiators for BUILD_SPECIAL in layering
683	if ( ! $ENV{'BUILD_SPECIAL'} )
684	{
685		if ( $allvariables->{'REGISTRYLAYERNAME'} ) { $allvariables->{'REGISTRYLAYERNAME'} = $allvariables->{'REGISTRYLAYERNAME'} . "_"; }
686		if (( $installer::globals::iswindowsbuild ) && ( $allvariables->{'BASISROOTNAME'} )) { $allvariables->{'BASISROOTNAME'} = $allvariables->{'BASISROOTNAME'} . "_"; }
687	}
688}
689
690####################################################
691# Removing .. in pathes
692####################################################
693
694sub simplify_path
695{
696	my ( $pathref ) = @_;
697
698	my $oldpath = $$pathref;
699
700	my $change = 0;
701
702	while ( $oldpath =~ /(^.*)(\Q$installer::globals::separator\E.*\w+?)(\Q$installer::globals::separator\E\.\.)(\Q$installer::globals::separator\E.*$)/ )
703	{
704		my $part1 = $1;
705		my $part2 = $4;
706		$oldpath = $part1 . $part2;
707		$change = 1;
708	}
709
710	if ( $change ) { $$pathref = $oldpath . "\n"; }
711}
712
713####################################################
714# Removing ending separators in pathes
715####################################################
716
717sub resolve_relative_pathes
718{
719	my ( $patharrayref ) = @_;
720
721	for ( my $i = 0; $i <= $#{$patharrayref}; $i++ )
722	{
723		installer::parameter::make_path_absolute(\${$patharrayref}[$i]);
724		simplify_path(\${$patharrayref}[$i]);
725	}
726}
727
728####################################################
729# Replacing variables inside zip list variables
730# Example: {milestone} to be replaced by
731# $installer::globals::lastminor
732####################################################
733
734sub replace_variables_in_ziplist_variables
735{
736	my ($blockref) = @_;
737
738	my $milestonevariable = $installer::globals::lastminor;
739	$milestonevariable =~ s/m//;
740	$milestonevariable =~ s/s/\./;
741
742	my $localminor = $installer::globals::lastminor;
743	if ( $installer::globals::minor ) { $localminor = $installer::globals::minor; }
744
745	my $buildidstringcws = $installer::globals::build . $localminor . "(Build:" . $installer::globals::buildid . ")";
746
747	# the environment variable CWS_WORK_STAMP is set only in CWS
748	if ( $ENV{'CWS_WORK_STAMP'} ) { $buildidstringcws = $buildidstringcws . "\[CWS\:" . $ENV{'CWS_WORK_STAMP'} . "\]"; }
749
750	for ( my $i = 0; $i <= $#{$blockref}; $i++ )
751	{
752		if ($installer::globals::lastminor) { ${$blockref}[$i] =~ s/\{milestone\}/$milestonevariable/; }
753		else { ${$blockref}[$i] =~ s/\{milestone\}//; }
754		if ( $localminor ) { ${$blockref}[$i] =~ s/\{minor\}/$localminor/; }
755		else { ${$blockref}[$i] =~ s/\{minor\}//; }
756		if ( $installer::globals::buildid ) { ${$blockref}[$i] =~ s/\{buildid\}/$installer::globals::buildid/; }
757		else { ${$blockref}[$i] =~ s/\{buildid\}//; }
758		if ( $installer::globals::build ) { ${$blockref}[$i] =~ s/\{buildsource\}/$installer::globals::build/; }
759		else { ${$blockref}[$i] =~ s/\{build\}//; }
760		${$blockref}[$i] =~ s/\{buildidcws\}/$buildidstringcws/;
761	}
762}
763
764###########################################################
765# Overwrite the vendor string in openoffice.lst that is defined in configure
766###########################################################
767
768sub overwrite_ooovendor
769{
770    my ($variableshashref) = @_;
771    $variableshashref->{'OOOVENDOR'} = $ENV{'OOO_VENDOR'} , if( defined $ENV{'OOO_VENDOR'}  && $ENV{'OOO_VENDOR'} ne "" );
772}
773
774###########################################################
775# Adding the lowercase variables into the variableshashref
776###########################################################
777
778sub add_variables_to_allvariableshashref
779{
780	my ($variableshashref) = @_;
781
782	my $lcvariable = lc($variableshashref->{'PRODUCTNAME'});
783	$variableshashref->{'LCPRODUCTNAME'} = $lcvariable;
784
785	if ($variableshashref->{'SHORT_PRODUCTEXTENSION'})
786	{
787		$variableshashref->{'LCPRODUCTEXTENSION'} = "\-" . lc($variableshashref->{'SHORT_PRODUCTEXTENSION'}); # including the "-" !
788	}
789	else
790	{
791		$variableshashref->{'LCPRODUCTEXTENSION'} = "";
792	}
793
794	if ( $installer::globals::patch ) { $variableshashref->{'PRODUCTADDON'} = $installer::globals::patchaddon; }
795	elsif ( $installer::globals::languagepack ) { $variableshashref->{'PRODUCTADDON'} = $installer::globals::languagepackaddon; }
796	else { $variableshashref->{'PRODUCTADDON'} = ""; }
797
798	my $localbuild = $installer::globals::build;
799	if ( $localbuild =~ /^\s*(\w+?)(\d+)\s*$/ ) { $localbuild = $2; }	# using "680" instead of "src680"
800	$variableshashref->{'PRODUCTMAJOR'} = $localbuild;
801
802	my $localminor = "";
803	if ( $installer::globals::minor ne "" ) { $localminor = $installer::globals::minor; }
804	else { $localminor = $installer::globals::lastminor; }
805	if ( $localminor =~ /^\s*\w(\d+)\w*\s*$/ ) { $localminor = $1; }
806	$variableshashref->{'PRODUCTMINOR'} = $localminor;
807
808	$variableshashref->{'PRODUCTBUILDID'} = $installer::globals::buildid;
809	$variableshashref->{'SYSTEM_LIBTEXTCAT_DATA'} = $ENV{'SYSTEM_LIBTEXTCAT_DATA'} , if( defined $ENV{'SYSTEM_LIBTEXTCAT_DATA'} && $ENV{'SYSTEM_LIBTEXTCAT_DATA'} ne "" );
810}
811
8121;
813