diff options
author | yye00 <yye00@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-08-16 17:26:48 +0000 |
---|---|---|
committer | yye00 <yye00@17b73243-c579-4c4c-a9d2-2d5706c11dac> | 2005-08-16 17:26:48 +0000 |
commit | 8c8a283caecd5acddb6466c79be1513aae2fb70c (patch) | |
tree | 642b03bc32935a83799268c00a00cd65d7d754c7 /lib/sbin/CSTUtils.pl | |
parent | 8bbd884aa6aa78bb0b60eae385f4d9ba0de92982 (diff) |
configuration.ccl fix. Please test and report if anything breaks
git-svn-id: http://svn.cactuscode.org/flesh/trunk@4109 17b73243-c579-4c4c-a9d2-2d5706c11dac
Diffstat (limited to 'lib/sbin/CSTUtils.pl')
-rw-r--r-- | lib/sbin/CSTUtils.pl | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/lib/sbin/CSTUtils.pl b/lib/sbin/CSTUtils.pl index c7043647..0090852d 100644 --- a/lib/sbin/CSTUtils.pl +++ b/lib/sbin/CSTUtils.pl @@ -749,4 +749,93 @@ sub GetOptionsFromEnv return \%options; } +#/*@@ +# @routine find_dep_cycles +# @date Fri Apr 15 20:47:00 2005 +# @author Josh Abadie +# @desc +# Iterates over all the thorns, and finds out if there are any cycles +# This function is the wrapper around the recursive one. +# @enddesc +#@@*/ +sub find_dep_cycles +{ + my(%thorns) = @_; + my(%visited) = {}; + my($stack,$keyu,$returned); + my $debug = 0; + + foreach $key (keys %thorns) + { + $key = uc ($key); + #next if($visted{$key} && 1 == $visted{$key}); + next if(1 == $visited{$key}); + print "testing $key for deps\n" if (1 == $debug); + $stack = $key." "; + $returned = &recurse_deps($key, \%thorns, $stack, \%visited); + $visted{$key} = 1; + if("" ne $returned) + { + print "Found cycle while testing $key for deps.[$returned]\n" if (1 == $debug); + return $returned; + } + } + return ""; +} + +#/*@@ +# @routine recurse_deps +# @date Fri Apr 15 20:47:00 2005 +# @author Josh Abadie +# @desc +# Iterates over all the thorns, and finds out if there are any cycles +# +# @enddesc +#@@*/ +sub recurse_deps +{ + my($key, $thornsTemp,$stack, $visitedTemp) = @_; + my %thorns = %$thornsTemp; + my %visited = %$visitedTemp; + my($depThorni,$loop,$returned,$temp); + my (@arr)=(); + my $debug = 0; + + # Iterates over all thorns this one depends on, and checks to see if any + # form a cycle. + foreach $depThorn (split(" ", uc($thorns{"\U$key\E"}))) + { + $depThorn = uc($depThorn); + + if($stack =~ /\b$depThorn\b/i) + { + $stack =~ /.*\b($depThorn\b.*)$/i; + $loop = $1.$depThorn; + return $loop; + } + else + { + # We don't have a cycle yet, so let's recurse on this thorn's deps. + $stack = $stack.$depThorn. ' '; + print "Recursing into $depThorn. Stack is [$stack]\n" if (1 == $debug); + $returned = &recurse_deps($depThorn, \%thorns, $stack, \%visited); + if("" ne $returned) + { + return $returned; + } + $visited{$depThorn} = 1; + $temp = $"; + $" = " "; + $stack =~ s/^(.*)\s*$/$1/; + $stack =~ s/^\s*(.*)$/$1/; + @arr = split(" ", $stack); + pop(@arr); + $stack = "@arr "; + $" = $temp; + } + } + $visited{$key} = 1; + return ""; +} + 1; |