summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvo Hinkelmann <ihi@openoffice.org>2007-08-20 14:29:05 +0000
committerIvo Hinkelmann <ihi@openoffice.org>2007-08-20 14:29:05 +0000
commit5ab0213df56ff074ab4f744ac8f2b3b143af9969 (patch)
treec016b529824c77a50ec3219d41c6c27155bded44
parenta61e4ad8f7462e627e3b2a4ce3fd0e80bc0187a0 (diff)
INTEGRATION: CWS native99 (1.6.4); FILE MERGED
2007/08/08 12:14:44 is 1.6.4.2: #i80470# allowing root module definition without gid_Module_Root 2007/08/07 13:57:54 is 1.6.4.1: #i80411# new scp linker to simplify package restructuring
-rw-r--r--solenv/bin/modules/par2script/module.pm401
1 files changed, 149 insertions, 252 deletions
diff --git a/solenv/bin/modules/par2script/module.pm b/solenv/bin/modules/par2script/module.pm
index 5b02093db820..cc5dbeb19f0b 100644
--- a/solenv/bin/modules/par2script/module.pm
+++ b/solenv/bin/modules/par2script/module.pm
@@ -4,9 +4,9 @@
#
# $RCSfile: module.pm,v $
#
-# $Revision: 1.6 $
+# $Revision: 1.7 $
#
-# last change: $Author: ihi $ $Date: 2007-07-12 11:17:28 $
+# last change: $Author: ihi $ $Date: 2007-08-20 15:29:05 $
#
# The Contents of this file are made available subject to
# the terms of GNU Lesser General Public License Version 2.1.
@@ -33,343 +33,240 @@
#
#*************************************************************************
-
package par2script::module;
use par2script::converter;
-use par2script::work;
+use par2script::exiter;
###########################################
-# Removing undefined gids automatically
+# Removing undefined gids
# from modules
###########################################
sub remove_from_modules
{
- my ($script) = @_;
+ my ($gid, $item) = @_;
- # if these 5 gids are not defined, they are automatically removed from the module
+ my $counter = 0;
- my $allfilegids = par2script::work::get_all_gids_from_script($script, "File");
- my $allproceduregids = par2script::work::get_all_gids_from_script($script, "Procedure");
- my $allcustomgids = par2script::work::get_all_gids_from_script($script, "Custom");
- my $alldirectorygids = par2script::work::get_all_gids_from_script($script, "Directory");
- my $allunixlinkgids = par2script::work::get_all_gids_from_script($script, "Unixlink");
-
- for ( my $i = 0; $i <= $#{$script}; $i++ )
- {
- my $oneline = ${$script}[$i];
+ if ( ! exists($par2script::globals::searchkeys{$item}) ) { par2script::exiter::exit_program("ERROR: Unknown type \"$item\" at modules.", "remove_from_modules"); }
+ my $searchkey = $par2script::globals::searchkeys{$item};
- my $modulename;
-
- if ( $oneline =~ /^\s*Module\s+(\w+)\s*$/ )
- {
- $modulegid = $1;
- next;
- }
+ my $allmodules = $par2script::globals::definitions{'Module'};
- if ( $oneline =~ /^\s*(\w+?)\s*\=\s*\((.*?)\)\s*\;\s*$/ )
+ my $onemodule;
+ foreach $onemodule (keys %{$allmodules})
+ {
+ if (( exists($allmodules->{$onemodule}->{$searchkey}) ) && ( $allmodules->{$onemodule}->{$searchkey} =~ /\b$gid\b/ ))
{
- my $key = $1;
- my $allassigneditemsstring = $2;
- my $defineditemgids;
-
- if ( $key eq "Files" ) { $defineditemgids = $allfilegids; }
- elsif ( $key eq "Dirs" ) { $defineditemgids = $alldirectorygids; }
- elsif ( $key eq "Procedures" ) { $defineditemgids = $allproceduregids; }
- elsif ( $key eq "Customs" ) { $defineditemgids = $allcustomgids; }
- elsif ( $key eq "Unixlinks" ) { $defineditemgids = $allunixlinkgids; }
- else { next; } # for instance "Styles"
+ my $infoline = "WARNING: Removing $gid because of missing definition\n";
+ # print $infoline;
+ push(@par2script::globals::logfileinfo, $infoline);
- my $allassigneditems = par2script::converter::convert_stringlist_into_array(\$allassigneditemsstring, ",");
+ $allmodules->{$onemodule}->{$searchkey} =~ s/\b$gid\b//;
+ $allmodules->{$onemodule}->{$searchkey} =~ s/\,\s*\,/\,/;
+ $allmodules->{$onemodule}->{$searchkey} =~ s/\(\s*\,\s*/\(/;
+ $allmodules->{$onemodule}->{$searchkey} =~ s/\s*\,\s*\)/\)/;
- for ( my $j = 0; $j <= $#{$allassigneditems}; $j++ )
+ if (( $allmodules->{$onemodule}->{$searchkey} =~ /\(\s*\,\s*\)/ ) ||
+ ( $allmodules->{$onemodule}->{$searchkey} =~ /\(\s*\)/ ))
{
- my $oneassigneditem = ${$allassigneditems}[$j];
-
- # is there a definition for this assigned item?
-
- my $itemisdefined = 0;
-
- for ( my $k = 0; $k <= $#{$defineditemgids}; $k++ )
- {
- if ( $oneassigneditem eq ${$defineditemgids}[$k] )
- {
- $itemisdefined = 1;
- last;
- }
- }
-
- if (! $itemisdefined)
- {
- my $infoline = "WARNING: Removing $oneassigneditem from Module $modulegid\n";
- # print $infoline;
- push(@par2script::globals::logfileinfo, $infoline);
-
- ${$script}[$i] =~ s/\b$oneassigneditem\b//;
- ${$script}[$i] =~ s/\,\s*\,/\,/;
- ${$script}[$i] =~ s/\(\s*\,\s*/\(/;
- ${$script}[$i] =~ s/\s*\,\s*\)/\)/;
-
- if (( ${$script}[$i] =~ /\(\s*\,\s*\)/ ) || ( ${$script}[$i] =~ /\(\s*\)/ ))
- {
- # this line can be removed
- splice(@{$script}, $i, 1);
- $i--; # decreasing the counter!
- }
- }
+ delete($allmodules->{$onemodule}->{$searchkey});
}
+
+ $counter++;
}
}
+
+ return $counter;
}
###########################################
-# Adding the collectors
-# to the root module
+# Removing undefined gids automatically
+# from modules
###########################################
-sub create_rootmodule
+sub remove_undefined_gids_from_modules
{
- my ($rootmodule, $allitemgids, $itemname) = @_;
+ # If assigned gids for "File", "Directory" or "Unixlink" are not defined,
+ # they are automatically removed from the module
- if ( $#{$allitemgids} > -1 )
+ foreach $item ( @par2script::globals::items_assigned_at_modules )
{
- my $oneline = "\t$itemname \= \(";
+ my $assignedgids = $par2script::globals::assignedgids{$item};
+ my $definedgids = $par2script::globals::definitions{$item};
- for ( my $i = 0; $i <= $#{$allitemgids}; $i++ )
+ my $gid;
+ foreach $gid ( keys %{$assignedgids} )
{
- my $onegid = ${$allitemgids}[$i];
-
- my $infoline = "WARNING: Adding $onegid to root module\n";
- # print $infoline;
-
- if ($oneline eq "") { $oneline = "\t\t\t\t"; }
-
- $oneline .= $onegid;
-
- if ( $i == $#{$allitemgids} ) { $oneline .= "\)\;"; }
- else { $oneline .= "\,"; }
-
- if ( length($oneline) > 100 )
+ if ( ! exists( $definedgids->{$gid} ))
{
- $oneline .= "\n";
- push(@{$rootmodule}, $oneline);
- $oneline = "";
+ # deleting entry in module definition
+ my $number_of_removals = remove_from_modules($gid, $item);
+ # decreasing counter in assignments
+ if ( $assignedgids->{$gid} > $number_of_removals ) { $assignedgids->{$gid} = $assignedgids->{$gid} - $number_of_removals; }
+ else { delete($assignedgids->{$gid}); }
}
-
- }
-
- if (! $oneline =~ /^\s*$/ )
- {
- $oneline .= "\n";
- push(@{$rootmodule}, $oneline);
}
}
}
-######################################################
-# Splitting one long line into several short lines
-######################################################
+############################################
+# Getting the gid of the root module. The
+# root module has no ParentID or an empty
+# ParentID.
+############################################
-sub make_multiliner
+sub get_rootmodule_gid
{
- my ($itemname, $allgidstring) = @_;
-
- my @newblock = ();
+ my $rootgid = "";
+ my $foundroot = 0;
- my $allitemgids = par2script::converter::convert_stringlist_into_array(\$allgidstring, ",");
+ my $allmodules = $par2script::globals::definitions{'Module'};
- if ( $#{$allitemgids} > -1 )
+ my $modulegid = "";
+ foreach $modulegid (keys %{$allmodules} )
{
- my $oneline = "\t$itemname \= \(";
+ # print "Module $modulegid\n";
+ # my $content = "";
+ # foreach $content (sort keys %{$allmodules->{$modulegid}}) { print "\t$content = $allmodules->{$modulegid}->{$content};\n"; }
+ # print "End\n";
+ # print "\n";
- for ( my $i = 0; $i <= $#{$allitemgids}; $i++ )
+ if (( ! exists($allmodules->{$modulegid}->{'ParentID'})) || ( $allmodules->{$modulegid}->{'ParentID'} eq "" ))
{
- my $onegid = ${$allitemgids}[$i];
-
- if ($oneline eq "") { $oneline = "\t\t\t\t"; }
-
- $oneline .= $onegid;
-
- if ( $i == $#{$allitemgids} ) { $oneline .= "\)\;"; }
- else { $oneline .= "\,"; }
-
- if ( length($oneline) > 100 )
- {
- $oneline .= "\n";
- push(@newblock, $oneline);
- $oneline = "";
- }
- }
-
- if (! $oneline =~ /^\s*$/ )
- {
- $oneline .= "\n";
- push(@newblock, $oneline);
+ 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"); }
+ $rootgid = $modulegid;
+ $foundroot = 1;
}
}
- return \@newblock;
-}
-
-###################################################
-# Shorten the lines that belong to modules, if
-# the length of the line is greater 100
-###################################################
-
-sub shorten_lines_at_modules
-{
- my ($script) = @_;
+ 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"); }
- my $ismoduleblock = 0;
-
- for ( my $i = 0; $i <= $#{$script}; $i++ )
- {
- my $oneline = ${$script}[$i];
-
- if ( $oneline =~ /^\s*Module\s+\w+\s*$/ ) { $ismoduleblock = 1; }
- if (( $oneline =~ /^\s*End\s*$/ ) && ( $ismoduleblock )) { $ismoduleblock = 0; }
-
- if ( $ismoduleblock )
- {
- if (( $oneline =~ /^\s*(\w+)\s*\=\s*\((.*)\)\s*\;\s*$/ ) && ( length($oneline) > 100 ))
- {
- # this line has to be splitted in several lines
- my $item = $1;
- my $allgidstring = $2;
-
- my $multilines = make_multiliner($item, $allgidstring);
- splice(@{$script}, $i, 1, @{$multilines});
- }
- }
- }
+ return $rootgid;
}
-###########################################
-# Adding defined gids automatically
-# to the root module
-###########################################
+####################################
+# Adding defined items without
+# assignment to the root module.
+####################################
sub add_to_root_module
{
- my ($script) = @_;
-
- my $rootmodulestartline = "";
+ # If defined gids for "File", "Directory" or "Unixlink" are not assigned,
+ # they are automatically assigned to the root module
- # if these 4 gids are defined and not added to another module, they are automatically added to the root module
+ my $rootmodulegid = get_rootmodule_gid();
- my $allfilegids = par2script::work::get_all_gids_from_script($script, "File");
- my $allproceduregids = par2script::work::get_all_gids_from_script($script, "Procedure");
- my $allcustomgids = par2script::work::get_all_gids_from_script($script, "Custom");
- my $alldirectorygids = par2script::work::get_all_gids_from_script($script, "Directory");
- my $allunixlinkgids = par2script::work::get_all_gids_from_script($script, "Unixlink");
-
- for ( my $i = 0; $i <= $#{$script}; $i++ )
+ my $item;
+ foreach $item ( @par2script::globals::items_assigned_at_modules )
{
- my $oneline = ${$script}[$i];
+ my $assignedgids = $par2script::globals::assignedgids{$item};
+ my $definedgids = $par2script::globals::definitions{$item};
+
+ my $gidstring = "";
- if (( $oneline =~ /^\s*Module\s+\w+\s*$/ ) && ( $rootmodulestartline eq "" )) # the first module is the root module
+ # Perhaps there are already items assigned to the root
+ if ( ! exists($par2script::globals::searchkeys{$item}) ) { par2script::exiter::exit_program("ERROR: Unknown type \"$item\" at modules.", "remove_from_modules"); }
+ my $modulekey = $par2script::globals::searchkeys{$item};
+ if ( exists($par2script::globals::definitions{'Module'}->{$rootmodulegid}->{$modulekey}) )
{
- $rootmodulestartline = $i;
+ $gidstring = $par2script::globals::definitions{'Module'}->{$rootmodulegid}->{$modulekey};
+ $gidstring =~ s/\(//;
+ $gidstring =~ s/\)//;
}
- if ( $oneline =~ /^\s*(\w+?)\s*\=\s*\((.*?)\)\s*\;\s*$/ )
+ my $gid;
+ foreach $gid ( keys %{$definedgids} )
{
- my $key = $1;
- my $allassigneditemsstring = $2;
- my $defineditemgids;
-
- if ( $key eq "Files" ) { $defineditemgids = $allfilegids; }
- elsif ( $key eq "Dirs" ) { $defineditemgids = $alldirectorygids; }
- elsif ( $key eq "Procedures" ) { $defineditemgids = $allproceduregids; }
- elsif ( $key eq "Customs" ) { $defineditemgids = $allcustomgids; }
- elsif ( $key eq "Unixlinks" ) { $defineditemgids = $allunixlinkgids; }
- else { next; } # for instance "Styles"
-
- my $allassigneditems = par2script::converter::convert_stringlist_into_array(\$allassigneditemsstring, ",");
-
- for ( my $j = 0; $j <= $#{$allassigneditems}; $j++ )
+ if ( ! exists( $assignedgids->{$gid} ))
{
- my $oneassigneditem = ${$allassigneditems}[$j];
-
- # this can be removed for the list for the root module
-
- for ( my $k = 0; $k <= $#{$defineditemgids}; $k++ )
+ if ( $gidstring eq "" )
+ {
+ $gidstring = $gid;
+ }
+ else
{
- if ( $oneassigneditem eq ${$defineditemgids}[$k] )
- {
- splice(@{$defineditemgids}, $k, 1);
- last;
- }
+ $gidstring = "$gidstring,$gid";
}
+
+ $assignedgids->{$gid} = 1;
}
}
- }
- # Now the four collectors contain only gids, that have to be added to the root module
- # The module begins at $rootmodulestartline
+ if ( $gidstring ne "" )
+ {
+ $gidstring = "\($gidstring\)";
+ $par2script::globals::definitions{'Module'}->{$rootmodulegid}->{$modulekey} = $gidstring;
+ }
+ }
+}
- for ( my $i = $rootmodulestartline; $i <= $#{$script}; $i++ )
- {
- my $oneline = ${$script}[$i];
+###################################################
+# Including \n in a very long string
+###################################################
- if ( $oneline =~ /^\s*End\s*$/ ) { last; }
+sub include_linebreaks
+{
+ my ($allgidstring) = @_;
- if ( $oneline =~ /^\s*(\w+)\s+\=\s+\((.*)\)\s*\;\s*$/ )
- {
- my $key = $1;
- my $allassigneditemsstring = $2;
- my $defineditemgids;
+ my $newline = "";
+ my $newlength = 0;
- if ( $key eq "Files" ) { $defineditemgids = $allfilegids; }
- elsif ( $key eq "Dirs" ) { $defineditemgids = $alldirectorygids; }
- elsif ( $key eq "Procedures" ) { $defineditemgids = $allproceduregids; }
- elsif ( $key eq "Customs" ) { $defineditemgids = $allcustomgids; }
- elsif ( $key eq "Unixlinks" ) { $defineditemgids = $allunixlinkgids; }
- else { next; } # for instance "Styles"
+ $allgidstring =~ s/\(//;
+ $allgidstring =~ s/\)//;
- my $allassigneditems = par2script::converter::convert_stringlist_into_array(\$allassigneditemsstring, "\,");
+ my $allgids = par2script::converter::convert_stringlist_into_array_2($allgidstring, ",");
- # adding the root module items to the collectors
+ if ( $#{$allgids} > -1 )
+ {
+ my $onegid;
+ foreach $onegid ( @{$allgids} )
+ {
+ $newline = "$newline$onegid,";
+ $newlength = $newlength + length($onegid) + 1; # +1 for the comma
- for ( my $j = 0; $j <= $#{$allassigneditems}; $j++ )
+ if ( $newlength > 80 )
{
- push(@{$defineditemgids}, ${$allassigneditems}[$j]);
+ $newline = $newline . "\n\t\t\t\t";
+ $newlength = 0;
}
-
- # then the existing lines can be removed
-
- splice(@{$script}, $i, 1);
- $i--; # decreasing the counter!
}
}
- # creation of the new block
+ $newline =~ s/,\s*$//;
+ $newline = "($newline)";
- my @rootmodule = ();
- my $rootmoduleref = \@rootmodule;
+ return $newline;
+}
- create_rootmodule($rootmoduleref, $alldirectorygids, "Dirs");
- create_rootmodule($rootmoduleref, $allfilegids, "Files");
- create_rootmodule($rootmoduleref, $allproceduregids, "Procedures");
- create_rootmodule($rootmoduleref, $allcustomgids, "Customs");
- create_rootmodule($rootmoduleref, $allunixlinkgids, "Unixlinks");
+###################################################
+# Shorten the lines that belong to modules, if
+# the length of the line is greater 100
+###################################################
- # and finally the new blocks can be inserted into the root module
+sub shorten_lines_at_modules
+{
+ my $item;
+ foreach $item ( @par2script::globals::items_assigned_at_modules )
+ {
+ if ( ! exists($par2script::globals::searchkeys{$item}) ) { par2script::exiter::exit_program("ERROR: Unknown type \"$item\" at modules.", "shorten_lines_at_modules"); }
+ my $searchkey = $par2script::globals::searchkeys{$item};
- my $insertline;
+ my $allmodules = $par2script::globals::definitions{'Module'};
- for ( my $i = $rootmodulestartline; $i <= $#{$script}; $i++ )
- {
- if ( ${$script}[$i] =~ /^\s*End\s*$/i )
+ my $onemodule;
+ foreach $onemodule (keys %{$allmodules})
{
- $insertline = $i;
- last;
+ if (( exists($allmodules->{$onemodule}->{$searchkey}) ) &&
+ ( length($allmodules->{$onemodule}->{$searchkey}) > 100 ))
+ {
+ # including "\n\t\t\t\t"
+ my $newstring = include_linebreaks($allmodules->{$onemodule}->{$searchkey});
+ $allmodules->{$onemodule}->{$searchkey} = $newstring;
+ }
}
}
-
- splice(@{$script}, $insertline, 0, @{$rootmoduleref});
-
}
1;