ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/BuildSystem/ToolDoc.pm
(Generate patch)

Comparing COMP/SCRAM/src/BuildSystem/ToolDoc.pm (file contents):
Revision 1.1 by williamc, Tue Apr 18 09:09:57 2000 UTC vs.
Revision 1.1.2.10 by williamc, Fri May 5 14:18:45 2000 UTC

# Line 0 | Line 1
1 + #
2 + # ToolDoc.pm
3 + #
4 + # Originally Written by Christopher Williams
5 + #
6 + # Description
7 + # -----------
8 + # SimpleDoc interface to initialise Tool objects
9 + #
10 + # Interface
11 + # ---------
12 + # new()         : A new ToolDoc object
13 + # tool(toolobj) : set the tool object for the class
14 + # setup(file,$name,$version) : setup a tool object from the specified file
15 + #                               return 0 for OK 1 for cancel
16 + # interactive([0|1]) : set the interactive node 0=off 1=on
17 +
18 + package BuildSystem::ToolDoc;
19 + require 5.004;
20 + use ActiveDoc::SimpleDoc;
21 +
22 + sub new {
23 +        my $class=shift;
24 +        $self={};
25 +        bless $self, $class;
26 +        $self->init();
27 +        return $self;
28 + }
29 +
30 + sub init {
31 +        my $self=shift;
32 +        $self->{switch}=ActiveDoc::SimpleDoc->new();
33 +        $self->{switch}->newparse("setup");
34 +        $self->{switch}->addtag("setup","Tool",\&Tool_Start, $self,    
35 +                                                "", $self,
36 +                                                \&Tool_End, $self);
37 +        $self->{switch}->addtag("setup","Lib",\&Lib, $self,    
38 +                                                "", $self,
39 +                                                "", $self);
40 +        $self->{switch}->addtag("setup","External",\&External_Start, $self,    
41 +                                                "", $self,
42 +                                                "", $self);
43 +        $self->{switch}->addtag("setup","Client",\&Client_start, $self,
44 +                                                "", $self,
45 +                                                \&Client_end, $self);
46 +        $self->{switch}->addtag("setup","Environment",
47 +                                                \&Environment_Start, $self,    
48 +                                                \&Env_text, $self,
49 +                                                \&Environment_End, $self);
50 +        $self->{switch}->grouptag("Tool","setup");
51 +        $self->{switch}->addtag("setup","Architecture",
52 +                                        \&Arch_Start,$self,
53 +                                        "", $self,
54 +                                        \&Arch_End,$self);
55 +        $self->{Arch}=1;
56 +        push @{$self->{ARCHBLOCK}}, $self->{Arch};
57 +
58 + }
59 +
60 + sub interactive {
61 +        my $self=shift;
62 +        
63 +        @_?$self->{interactive}=shift
64 +          :((defined $self->{interactive})?$self->{interactive}:0);
65 + }
66 +
67 + sub tool {
68 +        my $self=shift;
69 +        $self->{tool}=shift;
70 + }
71 +
72 + sub setup {
73 +        my $self=shift;
74 +        my $file=shift;
75 +        my $name=shift;
76 +        my $version=shift;
77 +
78 +        $self->{ToolEnv}{'SCRAMtoolname'}=$name;
79 +        $self->{ToolEnv}{'SCRAMtoolversion'}=$version;
80 +        $self->{ToolEnv}{'SCRAM_ARCH'}=$ENV{'SCRAM_ARCH'};
81 +
82 +        $name=~tr[A-Z][a-z];
83 +        $self->{tool}->name($name);
84 +        $self->{tool}->version($version);
85 +        $self->{switch}->filetoparse($file);
86 +        $self->{toolfound}=1;
87 +        $self->{switch}->parse("setup");
88 +        return $self->{toolfound};
89 + }
90 +
91 + sub featuretext {
92 +        my $self=shift;
93 +        my $feature=shift;
94 +
95 +        if ( @_ ) {
96 +          $self->{featuretext}{$feature}=shift;
97 +        }
98 +        else {
99 +          return ($self->{featuretext}{$feature});
100 +        }
101 + }
102 +
103 + sub _checkdefault {
104 +        my $self=shift;
105 +        my $hashref=shift;
106 +
107 +        if ( defined $$hashref{'default'} ) { #check default
108 +          my $default;
109 +          foreach $default ( split /:/, $$hashref{'default'} ) {
110 +            $default=~s/\"//;
111 +            if ($self->_testlocation($default,
112 +               [ $self->{tool}->getfeature($$hashref{'type'})] )) { return 1; }
113 +          }
114 +        }
115 +        return 0;
116 + }
117 +
118 + sub _testlocation {
119 +        my $self=shift;
120 +        my $default=shift;
121 +        my $testfiles=shift;
122 +        my $OK='false';
123 +        my $file;
124 +
125 +        chomp $default;
126 +        $default=$self->_expandvars($default);
127 +        print "Trying $default .... ";
128 +        if ( -f $default ) {
129 +                $OK="true";
130 +        }
131 +        else {
132 +          my $fh=FileHandle->new();
133 +          opendir $fh,  $default or do { print "No \n"; return 0; };
134 +         ($#{$testfiles}==-1) ? $OK='false' : $OK='true';
135 +          print "\n";
136 +          my @files=readdir $fh;
137 +          undef $fh;
138 +          foreach $file ( @$testfiles ) {
139 +                print "   Checking for $file .... ";
140 +                # now check that the required files are actually there
141 +                if ( ( $number = grep /\Q$file\L/, @files) == 0 ) {
142 +                   $OK='false';
143 +                   print "not found\n";
144 +                   last;
145 +                }
146 +                print "found\n";
147 +          }
148 +        }
149 +        if ( $OK eq 'true' ) {
150 +                print "Directory Check Complete\n";
151 +                return 1
152 +        }
153 +        return 0
154 + }
155 +
156 + sub _expandvars {
157 +        my $self=shift;
158 +        my $string=shift;
159 +
160 +        return "" , if ( ! defined $string );
161 +        $string=~s{
162 +                \$\((\w+)\)
163 +        }{
164 +          if (defined $self->{ToolEnv}{$1}) {
165 +                $self->_expandvars($self->{ToolEnv}{$1});
166 +          } else {
167 +                "\$$1";
168 +          }
169 +        }egx;
170 +        $string=~s{
171 +                \$(\w+)
172 +        }{
173 +          if (defined $self->{ToolEnv}{$1}) {
174 +                $self->_expandvars($self->{ToolEnv}{$1});
175 +          } else {
176 +                "\$$1";
177 +          }
178 +        }egx;
179 +        return $string;
180 + }
181 +
182 +
183 + sub _askuser {
184 +        my $self=shift;
185 +        my $querystring=shift;
186 +        my $varname=shift;
187 +
188 +        print $self->featuretext($self->{EnvContext});
189 +        for  ( ;; ) {
190 +         print "\n".$querystring." (RETURN to log as missing)\nset $varname = ";
191 +         $path=<STDIN>;
192 +         chomp $path;
193 +         if ( $path ne "" ) {
194 +          if ( defined $self->{'client'}) { # must be a location
195 +           if ( $self->_testlocation($path , "H", $Envtype{$type} )) {
196 +             return $path;
197 +           }
198 +           print "Error : ".$path." does not exist.\n";
199 +           next;
200 +          }
201 +         }
202 +         else {
203 +           return $path;
204 +         }
205 +        } #end for
206 +
207 + }
208 +
209 + # -- Tag Routines
210 +
211 + sub Client_start {
212 +        my $self=shift;
213 +        my $name=shift;
214 +        my $hashref=shift;
215 +
216 +        if ( $self->{Arch} ) {
217 +          $self->{'client'}=1;
218 +        }
219 + }
220 +
221 + sub Client_end {
222 +        my $self=shift;
223 +        if ( $self->{Arch} ) {
224 +        undef $self->{'client'};
225 +        }
226 + }
227 +        
228 + sub Tool_Start {
229 +        my $self=shift;
230 +        my $name=shift;
231 +        my $hashref=shift;
232 +
233 +        $self->{switch}->checktag($name, $hashref, 'name');
234 +        $self->{switch}->checktag($name, $hashref, 'version');
235 +        $self->{switch}->opengroup("Toolactive");
236 +
237 +        # lower case the name
238 +        $$hashref{'name'}=~tr[A-Z][a-z];
239 +        # make sure we only pick up the tool requested
240 +        if ( ( $self->{tool}->name() eq $$hashref{'name'} ) &&
241 +                ($self->{tool}->version() eq $$hashref{'version'})) {
242 +          $self->{switch}->
243 +                allowgroup("Toolactive",$self->{switch}->currentparsename());
244 +          $self->{ToolEnv}{'SCRAMtoolname'}=$$hashref{'name'};
245 +          $self->{ToolEnv}{'SCRAMtoolversion'}=$$hashref{'version'};
246 +          $self->{toolfound}=0;
247 +        }
248 +        else {
249 +          $self->{switch}->disallowgroup("Toolactive",
250 +                                $self->{switch}->currentparsename());
251 +        }
252 + }
253 +
254 + sub Tool_End {
255 +        my $self=shift;
256 +        my $name=shift;
257 +        my $hashref=shift;
258 +
259 +        $self->{switch}->closegroup("Toolactive");
260 + }
261 +
262 + sub Environment_Start {
263 +        my $self=shift;
264 +        my $name=shift;
265 +        my $hashref=shift;
266 +
267 +        $self->{switch}->checktag($name, $hashref, 'name');
268 +        if ( $self->{Arch} ) {
269 +          if ( defined $self->{EnvContext} ) {
270 +            $self->parserror(" Attempted to open new <$name> context".
271 +                        " without closing the previous one");
272 +          }
273 +          $self->{currentenvtext}="";
274 +          $self->{EnvContext}=$$hashref{'name'};
275 +          undef $self->{Envvalue};
276 +          if ( exists $$hashref{'type'} ) {
277 +            $$hashref{'type'}=~tr[A-Z][a-z];
278 +            $self->{tool}->type($$hashref{'name'},$$hashref{'type'});
279 +          }
280 +          if ( exists $$hashref{'value'}) {
281 +            $self->{Envvalue}=$$hashref{'value'};
282 +          }
283 +          elsif ( ! $self->interactive() ) {
284 +           # check the environment
285 +           if ( defined $ENV{$$hashref{'name'}} ) {
286 +            $self->{Envvalue}=$ENV{$$hashref{'name'}};
287 +           }
288 +           elsif ( $self->_checkdefault($hashref) ) {
289 +            $self->{Envvalue}=$$hashref{'default'};
290 +           }
291 +          }
292 +        }
293 + }
294 +
295 + sub Env_text {
296 +        my $self=shift;
297 +        my $name=shift;
298 +        my $string=shift;
299 +
300 +        if ( $self->{Arch} ) {
301 +          $self->{currentenvtext}=$self->{currentenvtext}.$string;
302 +        }
303 + }
304 +
305 + sub Environment_End {
306 +        my $self=shift;
307 +        my $name=shift;
308 +
309 +        if ( $self->{Arch} ) {
310 +          if ( ! defined $self->{EnvContext} ) {
311 +            $self->{switch}->parseerror("</$name> without an opening context");
312 +          }
313 +          # - set the help text
314 +          $self->featuretext($self->{EnvContext},$self->{currentenvtext});
315 +          if ( ! defined $self->{Envvalue} ) {
316 +            $self->{Envvalue}=$self->_askuser("Please Enter the Value Below:",
317 +                        $self->{EnvContext});
318 +          }
319 +          $self->{Envvalue}=$self->_expandvars($self->{Envvalue});
320 +          $self->{tool}->addfeature($self->{EnvContext}, $self->{Envvalue});
321 +          $self->{ToolEnv}{$self->{EnvContext}}=$self->{Envvalue};
322 +          undef $self->{EnvContext};
323 +          undef $self->{Envvalue};
324 +        }
325 + }
326 +
327 + sub Lib {
328 +        my $self=shift;
329 +        my $name=shift;
330 +        my $hashref=shift;
331 +
332 +        $self->{switch}->checktag($name, $hashref, 'name');
333 +        if ( $self->{Arch} ) {
334 +          $self->{tool}->addfeature("lib",$$hashref{'name'});
335 +        }
336 + }
337 +
338 + sub External_Start {
339 +        my $self=shift;
340 +        my $name=shift;
341 +        my $hashref=shift;
342 +
343 +        $self->{switch}->checktag($name, $hashref,'ref');
344 +        if ( $self->{Arch} ) {
345 +          $self->{tool}->addfeature("_externals",$$hashref{'ref'});
346 +        }
347 + }
348 +
349 + sub Arch_Start {
350 +        my $self=shift;
351 +        my $name=shift;
352 +        my $hashref=shift;
353 +
354 +        $self->{switch}->checktag($name, $hashref,'name');
355 +        ( ($ENV{SCRAM_ARCH}=~/$$hashref{name}.*/) )? ($self->{Arch}=1)
356 +                                                : ($self->{Arch}=0);
357 +        push @{$self->{ARCHBLOCK}}, $self->{Arch};
358 + }
359 +
360 + sub Arch_End {
361 +        my $self=shift;
362 +        my $name=shift;
363 +
364 +        pop @{$self->{ARCHBLOCK}};
365 +        $self->{Arch}=$self->{ARCHBLOCK}[$#{$self->{ARCHBLOCK}}];
366 + }
367 +
368 +

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines