root/juggler/trunk/JugglerConfigure.pm

Revision 20974, 5.0 kB (checked in by patrick, 7 months ago)

Copyright update.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1 # ************** <auto-copyright.pl BEGIN do not edit this line> **************
2 #
3 # VR Juggler is (C) Copyright 1998-2008 by Iowa State University
4 #
5 # Original Authors:
6 #   Allen Bierbaum, Christopher Just,
7 #   Patrick Hartling, Kevin Meinert,
8 #   Carolina Cruz-Neira, Albert Baker
9 #
10 # This library is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU Library General Public
12 # License as published by the Free Software Foundation; either
13 # version 2 of the License, or (at your option) any later version.
14 #
15 # This library 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 GNU
18 # Library General Public License for more details.
19 #
20 # You should have received a copy of the GNU Library General Public
21 # License along with this library; if not, write to the
22 # Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 # Boston, MA 02111-1307, USA.
24 #
25 # *************** <auto-copyright.pl END do not edit this line> ***************
26
27 package JugglerConfigure;
28
29 use strict 'vars';
30 use vars qw($DEFAULT_MODULE);
31
32 sub parseConfigFile($);
33
34 $DEFAULT_MODULE = '';
35 my %MODULES     = ();
36
37 sub parseConfigFile ($)
38 {
39    my $cfg = shift;
40    open(CFG, "$cfg") or die "ERROR: Could not read from $cfg: $!\n";
41
42    my($cfg_file, $line);
43    while ( $line = <CFG> )
44    {
45       $line =~ s/(#|\/\/).*$//;
46       $cfg_file .= "$line";
47    }
48
49    close(CFG);
50
51    while ( $cfg_file !~ /^\s*$/ )
52    {
53       if ( $cfg_file =~ /^\s*(\S+)\s*{(.+?)}\s*/s )
54       {
55          my $mod   = "$1";
56          my $deps  = "$2";
57          $cfg_file = $';
58
59          $MODULES{"$mod"} = new JugglerModule("$mod");
60
61          while ( $deps !~ /^\s*$/ )
62          {
63             # Match a dependency on another module.
64             if ( $deps =~ /^\s*depend\s+(\S+);/ )
65             {
66                $deps = $';
67                my $module_name = "$1";
68
69                die "ERROR: No such module $module_name for $mod dependency\n"
70                   unless defined($MODULES{"$module_name"});
71
72                $MODULES{"$mod"}->addDependencies($MODULES{"$module_name"}->getDependencies());
73             }
74             # Match a dependency on a package.  This may have environment
75             # variable settings, or it may just be a path.
76             elsif ( $deps =~ /\s*(\S.+?)(:\s+(.+?)|\s*);/ )
77             {
78                $deps = $';
79
80                my $dep_path = "$1";
81                my %vars = ();
82
83                if ( defined($3) )
84                {
85                   my @var_list = split(/\s*,\s*/, "$3");
86
87                   my $var;
88                   foreach $var ( @var_list )
89                   {
90                      $var =~ /\s*(\w+)=(\S+)\s*/;
91                      $vars{"$1"} = "$2";
92                   }
93                }
94
95                $MODULES{"$mod"}->addDependency(new ModuleDependency("$dep_path",
96                                                                     \%vars));
97             }
98             else
99             {
100                # XXX: Not quite right...
101                $deps ='';
102             }
103          }
104       }
105       elsif ( $cfg_file =~ /^Default:\s+(\S+)\s*$/m )
106       {
107          $DEFAULT_MODULE = "$1";
108          $cfg_file       = $';
109       }
110
111       $cfg_file =~ s/^\s*//;
112    }
113
114    return %MODULES;
115 }
116
117 package JugglerModule;
118
119 sub new ($$)
120 {
121    my $class = shift;
122    my $name  = shift;
123
124    return bless
125    {
126       'name' => $name,          # Name of this module
127       'deps' => []              # Array of ModuleDependecy objects
128    }, $class;
129 }
130
131 sub getName ($)
132 {
133    my $this = shift;
134    return $this->{'name'};
135 }
136
137 sub getDependencies ($)
138 {
139    my $this = shift;
140    return @{$this->{'deps'}};
141 }
142
143 sub addDependency ($$)
144 {
145    my $this = shift;
146    my $dep  = shift;
147    push(@{$this->{'deps'}}, $dep) unless $this->hasDependency($dep);
148 }
149
150 sub addDependencies ($@)
151 {
152    my $this = shift;
153
154    # The $MODULES entry for $module_name contains an array of hash references.
155    # We just copy those references into the array for the current module
156    # ($this).  Simple, no?
157    my $dep;
158    foreach $dep ( @_ )
159    {
160       $this->addDependency($dep) unless $this->hasDependency($dep);
161    }
162 }
163
164 sub hasDependency ($$)
165 {
166    my $this    = shift;
167    my $new_dep = shift;
168
169    my $has_dependency = 0;
170
171    my $cur_dep;
172    foreach $cur_dep ( $this->getDependencies() )
173    {
174       if ( $cur_dep->getPath() eq $new_dep->getPath() )
175       {
176          $has_dependency = 1;
177          last;
178       }
179    }
180
181    return $has_dependency;
182 }
183
184 package ModuleDependency;
185
186 sub new ($$;$)
187 {
188    my $class = shift;
189    my $path  = shift;
190    my $env   = shift || {};
191    
192    return bless
193    {
194       'path' => $path,          # Path to this dependency
195       'env'  => $env            # Reference to environment variable hash
196    }, $class;
197 }
198
199 sub getPath ($)
200 {
201    my $this = shift;
202    return $this->{'path'};
203 }
204
205 sub getEnvironment ($)
206 {
207    my $this = shift;
208    return %{$this->{'env'}};
209 }
210
211 sub getEnvironmentValue ($$)
212 {
213    my $this = shift;
214    my $key  = shift;
215
216    return ${$this->{'env'}}{"$key"};
217 }
218
219 1;
Note: See TracBrowser for help on using the browser.