1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: module.pm,v $
13 # This file is part of OpenOffice.org.
15 # OpenOffice.org is free software: you can redistribute it and/or modify
16 # it under the terms of the GNU Lesser General Public License version 3
17 # only, as published by the Free Software Foundation.
19 # OpenOffice.org is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 # GNU Lesser General Public License version 3 for more details
23 # (a copy is included in the LICENSE file that accompanied this code).
25 # You should have received a copy of the GNU Lesser General Public License
26 # version 3 along with OpenOffice.org. If not, see
27 # <http://www.openoffice.org/license.html>
28 # for a copy of the LGPLv3 License.
30 #*************************************************************************
32 package par2script
::module
;
34 use par2script
::converter
;
35 use par2script
::exiter
;
37 ###########################################
38 # Removing undefined gids
40 ###########################################
42 sub remove_from_modules
44 my ($gid, $item) = @_;
48 if ( ! exists($par2script::globals
::searchkeys
{$item}) ) { par2script
::exiter
::exit_program
("ERROR: Unknown type \"$item\" at modules.", "remove_from_modules"); }
49 my $searchkey = $par2script::globals
::searchkeys
{$item};
51 my $allmodules = $par2script::globals
::definitions
{'Module'};
54 foreach $onemodule (keys %{$allmodules})
56 if (( exists($allmodules->{$onemodule}->{$searchkey}) ) && ( $allmodules->{$onemodule}->{$searchkey} =~ /\b$gid\b/ ))
58 my $infoline = "WARNING: Removing $gid because of missing definition\n";
60 push(@par2script::globals
::logfileinfo
, $infoline);
62 $allmodules->{$onemodule}->{$searchkey} =~ s/\b$gid\b//;
63 $allmodules->{$onemodule}->{$searchkey} =~ s/\,\s*\,/\,/;
64 $allmodules->{$onemodule}->{$searchkey} =~ s/\(\s*\,\s*/\(/;
65 $allmodules->{$onemodule}->{$searchkey} =~ s/\s*\,\s*\)/\)/;
67 if (( $allmodules->{$onemodule}->{$searchkey} =~ /\(\s*\,\s*\)/ ) ||
68 ( $allmodules->{$onemodule}->{$searchkey} =~ /\(\s*\)/ ))
70 delete($allmodules->{$onemodule}->{$searchkey});
80 ###########################################
81 # Removing undefined gids automatically
83 ###########################################
85 sub remove_undefined_gids_from_modules
87 # If assigned gids for "File", "Directory" or "Unixlink" are not defined,
88 # they are automatically removed from the module
90 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
92 my $assignedgids = $par2script::globals
::assignedgids
{$item};
93 my $definedgids = $par2script::globals
::definitions
{$item};
96 foreach $gid ( keys %{$assignedgids} )
98 if ( ! exists( $definedgids->{$gid} ))
100 # deleting entry in module definition
101 my $number_of_removals = remove_from_modules
($gid, $item);
102 # decreasing counter in assignments
103 if ( $assignedgids->{$gid} > $number_of_removals ) { $assignedgids->{$gid} = $assignedgids->{$gid} - $number_of_removals; }
104 else { delete($assignedgids->{$gid}); }
110 ############################################
111 # Getting the gid of the root module. The
112 # root module has no ParentID or an empty
114 ############################################
116 sub get_rootmodule_gid
121 my $allmodules = $par2script::globals
::definitions
{'Module'};
124 foreach $modulegid (keys %{$allmodules} )
126 # print "Module $modulegid\n";
128 # foreach $content (sort keys %{$allmodules->{$modulegid}}) { print "\t$content = $allmodules->{$modulegid}->{$content};\n"; }
132 if (( ! exists($allmodules->{$modulegid}->{'ParentID'})) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
134 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"); }
135 $rootgid = $modulegid;
140 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"); }
145 ####################################
146 # Adding defined items without
147 # assignment to the root module.
148 ####################################
150 sub add_to_root_module
152 # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
153 # they are automatically assigned to the root module
155 my $rootmodulegid = get_rootmodule_gid
();
158 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
160 my $assignedgids = $par2script::globals
::assignedgids
{$item};
161 my $definedgids = $par2script::globals
::definitions
{$item};
165 # Perhaps there are already items assigned to the root
166 if ( ! exists($par2script::globals
::searchkeys
{$item}) ) { par2script
::exiter
::exit_program
("ERROR: Unknown type \"$item\" at modules.", "remove_from_modules"); }
167 my $modulekey = $par2script::globals
::searchkeys
{$item};
168 if ( exists($par2script::globals
::definitions
{'Module'}->{$rootmodulegid}->{$modulekey}) )
170 $gidstring = $par2script::globals
::definitions
{'Module'}->{$rootmodulegid}->{$modulekey};
171 $gidstring =~ s/\(//;
172 $gidstring =~ s/\)//;
176 foreach $gid ( keys %{$definedgids} )
178 if ( ! exists( $assignedgids->{$gid} ))
180 if ( $gidstring eq "" )
186 $gidstring = "$gidstring,$gid";
189 $assignedgids->{$gid} = 1;
193 if ( $gidstring ne "" )
195 $gidstring = "\($gidstring\)";
196 $par2script::globals
::definitions
{'Module'}->{$rootmodulegid}->{$modulekey} = $gidstring;
201 ###################################################
202 # Including \n in a very long string
203 ###################################################
205 sub include_linebreaks
207 my ($allgidstring) = @_;
212 $allgidstring =~ s/\(//;
213 $allgidstring =~ s/\)//;
215 my $allgids = par2script
::converter
::convert_stringlist_into_array_2
($allgidstring, ",");
217 if ( $#{$allgids} > -1 )
220 foreach $onegid ( @
{$allgids} )
222 $newline = "$newline$onegid,";
223 $newlength = $newlength + length($onegid) + 1; # +1 for the comma
225 if ( $newlength > 80 )
227 $newline = $newline . "\n\t\t\t\t";
233 $newline =~ s/,\s*$//;
234 $newline = "($newline)";
239 ###################################################
240 # Shorten the lines that belong to modules, if
241 # the length of the line is greater 100
242 ###################################################
244 sub shorten_lines_at_modules
247 foreach $item ( @par2script::globals
::items_assigned_at_modules
)
249 if ( ! exists($par2script::globals
::searchkeys
{$item}) ) { par2script
::exiter
::exit_program
("ERROR: Unknown type \"$item\" at modules.", "shorten_lines_at_modules"); }
250 my $searchkey = $par2script::globals
::searchkeys
{$item};
252 my $allmodules = $par2script::globals
::definitions
{'Module'};
255 foreach $onemodule (keys %{$allmodules})
257 if (( exists($allmodules->{$onemodule}->{$searchkey}) ) &&
258 ( length($allmodules->{$onemodule}->{$searchkey}) > 100 ))
260 # including "\n\t\t\t\t"
261 my $newstring = include_linebreaks
($allmodules->{$onemodule}->{$searchkey});
262 $allmodules->{$onemodule}->{$searchkey} = $newstring;