merge the formfield patch from ooo-build
[ooovba.git] / solenv / bin / modules / par2script / module.pm
blobcd229f7dffd4bbfe8fd74b744e8823a693d36c1f
1 #*************************************************************************
3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 #
5 # Copyright 2008 by Sun Microsystems, Inc.
7 # OpenOffice.org - a multi-platform office productivity suite
9 # $RCSfile: module.pm,v $
11 # $Revision: 1.8 $
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
39 # from modules
40 ###########################################
42 sub remove_from_modules
44 my ($gid, $item) = @_;
46 my $counter = 0;
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'};
53 my $onemodule;
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";
59 # print $infoline;
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});
73 $counter++;
77 return $counter;
80 ###########################################
81 # Removing undefined gids automatically
82 # from modules
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};
95 my $gid;
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
113 # ParentID.
114 ############################################
116 sub get_rootmodule_gid
118 my $rootgid = "";
119 my $foundroot = 0;
121 my $allmodules = $par2script::globals::definitions{'Module'};
123 my $modulegid = "";
124 foreach $modulegid (keys %{$allmodules} )
126 # print "Module $modulegid\n";
127 # my $content = "";
128 # foreach $content (sort keys %{$allmodules->{$modulegid}}) { print "\t$content = $allmodules->{$modulegid}->{$content};\n"; }
129 # print "End\n";
130 # print "\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;
136 $foundroot = 1;
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"); }
142 return $rootgid;
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();
157 my $item;
158 foreach $item ( @par2script::globals::items_assigned_at_modules )
160 my $assignedgids = $par2script::globals::assignedgids{$item};
161 my $definedgids = $par2script::globals::definitions{$item};
163 my $gidstring = "";
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/\)//;
175 my $gid;
176 foreach $gid ( keys %{$definedgids} )
178 if ( ! exists( $assignedgids->{$gid} ))
180 if ( $gidstring eq "" )
182 $gidstring = $gid;
184 else
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) = @_;
209 my $newline = "";
210 my $newlength = 0;
212 $allgidstring =~ s/\(//;
213 $allgidstring =~ s/\)//;
215 my $allgids = par2script::converter::convert_stringlist_into_array_2($allgidstring, ",");
217 if ( $#{$allgids} > -1 )
219 my $onegid;
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";
228 $newlength = 0;
233 $newline =~ s/,\s*$//;
234 $newline = "($newline)";
236 return $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
246 my $item;
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'};
254 my $onemodule;
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;