1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2000, 2010 Oracle and/or its affiliates.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # This file is part of OpenOffice.org.
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.
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).
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.
26 #*************************************************************************
28 package par2script
::module
;
30 use par2script
::converter
;
31 use par2script
::exiter
;
33 ###########################################
34 # Removing undefined gids
36 ###########################################
38 sub remove_from_modules
40 my ($gid, $item) = @_;
44 if ( ! exists($par2script::globals
::searchkeys
{$item}) ) { par2script
::exiter
::exit_program
("ERROR: Unknown type \"$item\" at modules.", "remove_from_modules"); }
45 my $searchkey = $par2script::globals
::searchkeys
{$item};
47 my $allmodules = $par2script::globals
::definitions
{'Module'};
50 foreach $onemodule (keys %{$allmodules})
52 if (( exists($allmodules->{$onemodule}->{$searchkey}) ) && ( $allmodules->{$onemodule}->{$searchkey} =~ /\b$gid\b/ ))
54 my $infoline = "WARNING: Removing $gid because of missing definition\n";
56 push(@par2script::globals
::logfileinfo
, $infoline);
58 $allmodules->{$onemodule}->{$searchkey} =~ s/\b$gid\b//;
59 $allmodules->{$onemodule}->{$searchkey} =~ s/\,\s*\,/\,/;
60 $allmodules->{$onemodule}->{$searchkey} =~ s/\(\s*\,\s*/\(/;
61 $allmodules->{$onemodule}->{$searchkey} =~ s/\s*\,\s*\)/\)/;
63 if (( $allmodules->{$onemodule}->{$searchkey} =~ /\(\s*\,\s*\)/ ) ||
64 ( $allmodules->{$onemodule}->{$searchkey} =~ /\(\s*\)/ ))
66 delete($allmodules->{$onemodule}->{$searchkey});
76 ###########################################
77 # Removing undefined gids automatically
79 ###########################################
81 sub remove_undefined_gids_from_modules
83 # If assigned gids for "File", "Directory" or "Unixlink" are not defined,
84 # they are automatically removed from the module
86 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
88 my $assignedgids = $par2script::globals
::assignedgids
{$item};
89 my $definedgids = $par2script::globals
::definitions
{$item};
92 foreach $gid ( keys %{$assignedgids} )
94 if ( ! exists( $definedgids->{$gid} ))
96 # deleting entry in module definition
97 my $number_of_removals = remove_from_modules
($gid, $item);
98 # decreasing counter in assignments
99 if ( $assignedgids->{$gid} > $number_of_removals ) { $assignedgids->{$gid} = $assignedgids->{$gid} - $number_of_removals; }
100 else { delete($assignedgids->{$gid}); }
106 ############################################
107 # Getting the gid of the root module. The
108 # root module has no ParentID or an empty
110 ############################################
112 sub get_rootmodule_gid
117 my $allmodules = $par2script::globals
::definitions
{'Module'};
120 foreach $modulegid (keys %{$allmodules} )
122 # print "Module $modulegid\n";
124 # foreach $content (sort keys %{$allmodules->{$modulegid}}) { print "\t$content = $allmodules->{$modulegid}->{$content};\n"; }
128 if (( ! exists($allmodules->{$modulegid}->{'ParentID'})) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
130 if ( $foundroot ) { par2script
::exiter
::exit_program
("ERROR: More than one Root module. Only one module without ParentID or with empty ParentID allowed ($rootgid and $modulegid).", "get_rootmodule_gid"); }
131 $rootgid = $modulegid;
136 if ( ! $foundroot ) { par2script
::exiter
::exit_program
("ERROR: Could not find Root module. Did not find module without ParentID or with empty ParentID.", "get_rootmodule_gid"); }
141 ####################################
142 # Adding defined items without
143 # assignment to the root module.
144 ####################################
146 sub add_to_root_module
148 # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
149 # they are automatically assigned to the root module
151 my $rootmodulegid = get_rootmodule_gid
();
154 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
156 my $assignedgids = $par2script::globals
::assignedgids
{$item};
157 my $definedgids = $par2script::globals
::definitions
{$item};
161 # Perhaps there are already items assigned to the root
162 if ( ! exists($par2script::globals
::searchkeys
{$item}) ) { par2script
::exiter
::exit_program
("ERROR: Unknown type \"$item\" at modules.", "remove_from_modules"); }
163 my $modulekey = $par2script::globals
::searchkeys
{$item};
164 if ( exists($par2script::globals
::definitions
{'Module'}->{$rootmodulegid}->{$modulekey}) )
166 $gidstring = $par2script::globals
::definitions
{'Module'}->{$rootmodulegid}->{$modulekey};
167 $gidstring =~ s/\(//;
168 $gidstring =~ s/\)//;
172 foreach $gid ( keys %{$definedgids} )
174 if ( ! exists( $assignedgids->{$gid} ))
176 if ( $gidstring eq "" )
182 $gidstring = "$gidstring,$gid";
185 $assignedgids->{$gid} = 1;
189 if ( $gidstring ne "" )
191 $gidstring = "\($gidstring\)";
192 $par2script::globals
::definitions
{'Module'}->{$rootmodulegid}->{$modulekey} = $gidstring;
197 ###################################################
198 # Including \n in a very long string
199 ###################################################
201 sub include_linebreaks
203 my ($allgidstring) = @_;
208 $allgidstring =~ s/\(//;
209 $allgidstring =~ s/\)//;
211 my $allgids = par2script
::converter
::convert_stringlist_into_array_2
($allgidstring, ",");
213 if ( $#{$allgids} > -1 )
216 foreach $onegid ( @
{$allgids} )
218 $newline = "$newline$onegid,";
219 $newlength = $newlength + length($onegid) + 1; # +1 for the comma
221 if ( $newlength > 80 )
223 $newline = $newline . "\n\t\t\t\t";
229 $newline =~ s/,\s*$//;
230 $newline = "($newline)";
235 ###################################################
236 # Shorten the lines that belong to modules, if
237 # the length of the line is greater 100
238 ###################################################
240 sub shorten_lines_at_modules
243 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
245 if ( ! exists($par2script::globals
::searchkeys
{$item}) ) { par2script
::exiter
::exit_program
("ERROR: Unknown type \"$item\" at modules.", "shorten_lines_at_modules"); }
246 my $searchkey = $par2script::globals
::searchkeys
{$item};
248 my $allmodules = $par2script::globals
::definitions
{'Module'};
251 foreach $onemodule (keys %{$allmodules})
253 if (( exists($allmodules->{$onemodule}->{$searchkey}) ) &&
254 ( length($allmodules->{$onemodule}->{$searchkey}) > 100 ))
256 # including "\n\t\t\t\t"
257 my $newstring = include_linebreaks
($allmodules->{$onemodule}->{$searchkey});
258 $allmodules->{$onemodule}->{$searchkey} = $newstring;